0
Swift Playground提供了以下代碼。如何在不傳入參數的情況下調用sayText(圖形:)? (顯然圖形已經放置在代碼的另一個段)如何在不傳入值的情況下使用參數調用函數? [Swift Playground]
// Speak the text of graphic.
func speakText(graphic: Graphic) {
speak(graphic.text)
}
func addGreeting(touch: Touch) {
if touch.previousPlaceDistance < 60 { return }
let greetings = ["howdy!", "hello", "hi", "ciao", "yo!", "hey!", "what’s up?"]
let greeting = greetings.randomItem
let graphic = Graphic(text: greeting)
graphic.textColor = #colorLiteral(red: 0.9686274529, green: 0.78039217, blue: 0.3450980484, alpha: 1)
graphic.fontName = .chalkduster
scene.place(graphic, at: touch.position)
graphic.rotation = randomDouble(from: -30, to: 30)
}
// Create and add Speak tool.
let speakTool = Tool(name: "Speak", emojiIcon: "")
speakTool.onGraphicTouched = speakText(graphic:)
scene.tools.append(speakTool)
THX閱讀更多關於這在功能類型節!你知道一個文檔或參考,我可以閱讀更多關於這個話題嗎? –
查看函數類型部分:https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID158 – vacawama