Created
November 19, 2015 15:08
-
-
Save william8th/b391bdc91760c43207f1 to your computer and use it in GitHub Desktop.
Objective-C Use ivars in init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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