Philipp Jahoda Philipp Jahoda - 1 year ago 69
iOS Question

How to write this objective-c block in swift syntax?

I have the following objective-c block.
I cannot figure out how to write it in swift syntax.
This is how the block is defined in objective-c:

formatter = ^(CGFloat value){

// do something with value

return "stringrepresentation";

Could someone be kind and show me the correct syntax?

ADDITIONAL Info: the "formatter" value needs to be of type

How to achieve this?

Answer Source

Look at closures.

{(/*Parameters*/) -> /*ReturnType*/ in
    // Statements

So this block would be:

{(value : CGFloat) -> String in
    // Do cool stuff
    retun "aString"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download