Tuesday, 15 June 2010

Porting an Objective-C block to Swift -



Porting an Objective-C block to Swift -

i porting game made in objective c swift way larn how port , how mix swift objective c , objective c swift.

but after lots of searching can't find how port line of code:

gccontrollerdirectionpadvaluechangedhandler dpadmovehandler = ^(gccontrollerdirectionpad *dpad, float xvalue, float yvalue) { }

only thing found piece of code apple:

swift

typealias gccontrollerdirectionpadvaluechangedhandler = (gccontrollerdirectionpad!, cfloat, cfloat) -> void

objective-c

typedef void (^gccontrollerdirectionpadvaluechangedhandler) (gccontrollerdirectionpad *dpad, float xvalue, float yvalue)

--

this code i've tried far, no luck.

var dpadmovehandler: gccontrollerdirectionpadvaluechangedhandler = (#dpad:gccontrollerdirectionpad, #xvalue:cfloat, #yvalue:cfloat) { }

that line declares objc block. typealias you're looking @ in swift closure type. equivalent code this:

var dpadmovehandler:gccontrollerdirectionpadvaluechangedhandler = { (dpad:gccontrollerdirectionpad!, xvalue:cfloat, yvalue:cfloat) -> () in homecoming }

read swift closures here.

objective-c swift

No comments:

Post a Comment