Re:Function hooking in Swift
by blarney_stone on Thursday June 19, 2014 @10:24AM
(#7916198)
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.
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.
Re:Function hooking in Swift
by ololoev on Thursday June 19, 2014 @12:00PM
(#7916784)
Well, 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.
From 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.