Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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