I don’t mean to start a code formatting holy war here, but I’m wondering if anyone has any advice on how to best format nested blocks in Objective-C.
Here’s some code I wrote today:
[UIView animateWithDuration:1.0
animations:^{
self.alpha = 0.5;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
winView.alpha = 1.0;
}
completion:^(BOOL finished){
winView.alpha = 0.0;
}];
}];
I pretty much let Xcode format it, and it’s not terrible. But I’m kinda afraid in six months I’ll stumble across this to fix some bug, and want to punch myself in the face.
Anyone have any pointers on how to make nested blocks as readable as possible?
The real issue here is methods that take multiple block arguments, which make it either ugly or hard to read. I haven’t written any real code that needs to use it yet, but one possibility is to separate the
}and];like this:This breaks the standard formatting of blocks (which keeps
}and];together), but I think it is slightly more readable.