Quickies

[categories] [index] [all (527)] [latest]

Cocoa Foundation
  1. When encountering the error message

    "Variable is not assignable (missing __block type specifier)"
    

    consider actually using the __block type specifier, so that the variable always live in the scope of the blocks declared within the variable lexical scope, and also in the copies of these blocks. It also means that the address of the variable may change over time. See Blocks Programming Topics for more.

    + (NSString *)myMethodWithDictionary:(NSDictionary *)d {
    
        __block NSString *s = nil; // s lives in block storage
    
        [d enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {    
            if( /* condition here */ ) {
                *stop = YES;
                s = @"xxx";
            }
        }];
    
        return s;
    }