3 ms·
I've seen this concern that there are no function pointers in swift, and it seems to come from a misunderstanding on what it means for functions to be first cla
by blarney_stone 12y ago
I've seen this concern that there are no function pointers in swift, and it seems to come from a misunderstanding on what it means for functions to be first class.
From https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ https://developer.apple.com/library/prerelease/ios/documenta... :
You use function types just like any other types in Swift. For example, you can define a constant or variable to be of a function type and assign an appropriate function to that variable:
var mathFunction: (Int, Int) -> Int = addTwoInts
mathFunction can now be passed around, fed in as a parameter in another function, etc. mathFunction is for all purposes a function pointer.
- ololoev 12y agoWell, there isn't any C-style function pointer (means you can not get it's raw address in memory to do something with it), but yeah — you can pass functions as arguments.