In Objective-C I do this:
@property (nonatomic, copy) void(^completion)(MyObject * obj);
What is the correct way to do this in swift?
The corresponding closure property would be declared as
class MyClass {
var completion : ((MyObject) -> Void)? // or ...! for an implicitly unwrapped optional
}
You can set the property like
completion = {
(obj : MyObject) -> Void in
// do something with obj ...
}
which can be shortened (due to the automatic type inference) to
completion = {
obj in
// do something with obj ...
}