Swift 调用没有括号的函数??[迅捷游乐场]

Swift 调用没有括号的函数??[迅捷游乐场],swift,swift-playground,Swift,Swift Playground,斯威夫特提供了以下代码。没有括号怎么可能调用squishEm函数?这不是函数和属性之间的语法区别吗 func squishEm() { // Iterate over graphics and squish each one. for graphic in graphics { squishGraphic(graphic: graphic) } } // Create and add Squish ’Em! button. let squishButton = Button(name:

斯威夫特提供了以下代码。没有括号怎么可能调用squishEm函数?这不是函数和属性之间的语法区别吗

func squishEm() {
// Iterate over graphics and squish each one.
for graphic in graphics {
    squishGraphic(graphic: graphic)
}
}

// Create and add Squish ’Em! button.
let squishButton = Button(name: "Squish ’Em!")
squishButton.onTap = squishEm
scene.button = squishButton
你不是在调用squishEm。您是说squishButton的onTap函数就是squishEm函数。当点击按钮时,它在内部使用parens调用squishEm

函数调用有括号。 对函数的引用不起作用


为了进一步阅读,我建议阅读中的部分函数类型。

这基本上与上一个问题相同。可能重复