I am attempting to traverse an array in order to calculate a value, modeled by the code below:
double foo = 0;
[sortedKeys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
foo += (NSNumber*)[obj doSomething].doubleValue
}];
However I get an error that foo is not scoped appropriately, how can I set foo up so that the block sees it and can modify it when it runs.
You should add
__blockto the declaration in order to be able to modify a variable from inside the block: