【发布时间】:2017-06-30 16:42:36
【问题描述】:
Swift Playground 提供了以下代码。不传入参数如何调用 speakText(graphic: )? (显然图形已经放在另一段代码中了)
// 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)
【问题讨论】: