Skip to content

Instantly share code, notes, and snippets.

@McZonk
Created January 17, 2013 15:43
Show Gist options
  • Save McZonk/4556864 to your computer and use it in GitHub Desktop.
Save McZonk/4556864 to your computer and use it in GitHub Desktop.
instancetype benefits
@interface Octopus : NSObject
+ (instancetype)octopus;
- (instancetype)init;
@property (nonatomic, assign) int legs;
@end
@implementation Octopus
+ (instancetype)octopus {
return [[Octopus alloc] init];
}
- (instancetype)init {
self = [super init];
if(self != nil) {
}
return self;
}
+ (int)someMethod {
int x = [Octopus octopus].legs;
int y = [[Octopus alloc] init].legs;
return x + y;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment