Skip to content

Instantly share code, notes, and snippets.

@william8th
Created November 19, 2015 15:08
Show Gist options
  • Select an option

  • Save william8th/b391bdc91760c43207f1 to your computer and use it in GitHub Desktop.

Select an option

Save william8th/b391bdc91760c43207f1 to your computer and use it in GitHub Desktop.
Objective-C Use ivars in init
@implementation WHYPerson
- (id)init {
self = [super init];
if (self) {
// It is recommended to use instance variables directly to initialise the object
_firstName = ...;
_lastName = ...;
_dateOfBirth = ...;
}
return self;
}
- (void)doSomething {
// We use message-passing to access properties in methods that are not responsible to initialise the object
NSLog([self firstName]);
}
...
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment