Skip to content

Instantly share code, notes, and snippets.

@jspahrsummers
Created May 5, 2011 05:07
Show Gist options
  • Save jspahrsummers/956568 to your computer and use it in GitHub Desktop.
Save jspahrsummers/956568 to your computer and use it in GitHub Desktop.
Following this behavior, how would you want to write it naturally?
- (NSString *)myMethod {
NSString *str = nil;
scope {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
scope(exit)
[pool drain];
str = [[NSMutableString alloc] initWithFormat:@"%i", 42];
for (int i = 0;i < 10;++i)
scope {
NSString *append = [something thatReturnsACopy];
scope(exit) {
[append release];
}
[str appendString:append];
}
}
return [str autorelease];
}
- (void)myOtherMethod {
scope {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
scope(exit)
[pool drain];
NSString *str = [NSString stringWithFormat:@"%i", 42];
if ([str length]) {
// done
return;
}
[self doMoreStuff];
if (done)
return;
[self doEvenMoreStuff];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment