2

In ObjectiveC i can define block which will be used many places like

typedef void (^APISuccessHandler)(RKObjectRequestOperation *operation, RKMappingResult *result);

and then use it in (for example) ViewController propery

@property (nonatomic, copy) APISuccessHandler successHandler;

How do same in swift?

1

1 Answer 1

3

Use typealias

typealias MyType=(str:String,num:Int)->()

Then,

var test:MyType = {(str,num) in
    println(str)
    println(num)
}

Execute the block

  test(str: "123", num: 1)

Output

123
1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.