diff options
author | Levi Bostian <levi.bostian@gmail.com> | 2014-01-01 17:20:23 -0600 |
---|---|---|
committer | Levi Bostian <levi.bostian@gmail.com> | 2014-01-08 12:44:16 -0600 |
commit | 5ad738af38b4642257f5036ac5ed7dbc27f4e187 (patch) | |
tree | 007d8a2cc1b654b6a1514809aca748e8a8ee3f5e /objective-c.html.markdown | |
parent | f81cba31b51130e0f92dca804799053a79adfb9f (diff) |
Add example of calling instance and class methods.
Diffstat (limited to 'objective-c.html.markdown')
-rw-r--r-- | objective-c.html.markdown | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/objective-c.html.markdown b/objective-c.html.markdown index a70351b5..e1834bf8 100644 --- a/objective-c.html.markdown +++ b/objective-c.html.markdown @@ -306,10 +306,11 @@ int main (int argc, const char * argv[]) // Methods +/- (return type)methodSignature:(Parameter Type *)parameterName; -// + for class method +// + for class method. + (NSString *)classMethod; ++ (MyClass *)myClassFromName:(NSString *)name; -// - for instance method +// - for instance methods. - (NSString *)instanceMethodWithParameter:(NSString *)string; - (NSNumber *)methodAParameterAsString:(NSString*)string andAParameterAsNumber:(NSNumber *)number; @@ -329,6 +330,14 @@ myClass.count = 45; NSLog(@"%i", myClass.count); // prints => 45 +// Call class methods: +NSString *classMethodString = [MyClass classMethod]; +MyClass *classFromName = [MyClass myClassFromName:@"Hello"]; + +// Call instance methods: +MyClass *myClass = [[MyClass alloc] init]; // Create MyClass object instance. +NSString *stringFromInstanceMethod = [myClass instanceMethodWithParameter:@"Hello"]; + // Implement the methods in an implementation (MyClass.m) file: @implementation MyClass { long distance; // Private access instance variable. |