diff options
author | Levi Bostian <levi.bostian@gmail.com> | 2013-12-21 17:37:19 -0600 |
---|---|---|
committer | Levi Bostian <levi.bostian@gmail.com> | 2013-12-30 18:14:04 -0600 |
commit | 643a3ec67bb5d7b453b4a4d59bbb8b254eccb0db (patch) | |
tree | ec22c408160861c4bf6ce1b101c334e9523bad58 /objective-c.html.markdown | |
parent | 5d5f3309faf8c6cf0bb5242ea7220e4ae772d6a3 (diff) |
Add getters and setters examples.
Diffstat (limited to 'objective-c.html.markdown')
-rw-r--r-- | objective-c.html.markdown | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/objective-c.html.markdown b/objective-c.html.markdown index 0a197e03..1cfe8ed6 100644 --- a/objective-c.html.markdown +++ b/objective-c.html.markdown @@ -233,9 +233,13 @@ int main (int argc, const char * argv[]) @property int count; @property (copy) NSString *name; // Copy the object during assignment. @property (readonly) id data; // Declare only a getter method. -// To access variable in implementation file, use '_' followed by variable name: +// To access public variable in implementation file, use '_' followed by variable name: _count = 5; -NSLog("%@", _count); // => prints 5 to console +NSLog(@"%d", _count); // prints => 5 +// To access public variable outside implementation file, @property generates setter method +// automatically. Method name is 'set' followed by @property variable name: +[objInitVar setCount:10]; // objInitVar = variable of object instance @property resides in. +NSLog(@"%@", [objInitVar count]); // prints => 10 // Methods +/- (return type)methodSignature:(Parameter Type *)parameterName; |