Blocks

Blocks as Variable

Objective-C

void (^blk)(int) = ^(int a) {
    // ...
};

Swift

let blk:(Int)->Void = { (a:Int) in 
    // ...
}

Blocks as Property

Objective-C

@interface Foo
@property void(^blk)(NSString *);
@end

@implementation Foo
-(void)method {
    blk = ^(NSString *msg){
        NSLog(@"In block: %@", msg);
        // ...
    };
}
@end

Swift

class Foo {
    var blk:(String!)->Void

    func method() {
        blk = { (msg:String!) in 
            NSLog("In block: %@", msg)
            // ...
        }
    }
}

Blocks as Parameter

Objective-C

@implementation Foo
-(void)method:(void (^)(int))blk {
    // ...
}
@end

Swift

class Foo {
    func method(blk:(Int)->Void) {
        // ...
    }
}

Direct Blocks Declaration

This pattern is not supported yet.

Objective-C

/** Not Supported yet */
void (^blk)(int) {
    // ...
};

Swift

/** Not Supported yet */
func blk() {
    // ...
};