martes, 19 de enero de 2016

iOS: Blocks

Property

@property (copy) void (^blockProperty)(void);

Method definition

- (void)beginTaskWithName:(NSString *)name completion:(void(^)(void))callback;

Inline implementation

[array enumerateObjectsUsingBlock:^ (id obj, NSUInteger idx, BOOL *stop) {
        NSLog(@"Object at index %lu is %@", idx, obj);
    }];

If you need to be able to change the value of a captured variable from within a block, you can use the __block storage type modifier on the original variable declaration.

__block int anInteger = 42;


No hay comentarios:

Publicar un comentario