Search code examples
iosobjective-cblock

Confused by use of = in block


void (^configureCell)(PhotoCell*, Photo*) = ^(PhotoCell* cell, Photo* photo) {
    cell.label.text = photo.name;
};

I never have seen before the "=" sign in a block, how does is work?

Thanks!


Solution

  • It's a block declaration which is assigned to the configureCell variable.

    This is block variable definition (like i.e. NSArray *array):

    void (^configureCell)(PhotoCell *, Photo *)
    

    This is block definition:

    ^(PhotoCell* cell, Photo* photo) {...}
    

    You can use this block like this:

    PhotoCell *cell = [PhotoCell ...];
    Photo *photo = [Photo ...];
    
    // Execute block
    configureCell(cell, photo);