diff options
| author | Yannick Loriot <yannick.loriot@gmail.com> | 2013-08-13 16:58:13 +0200 | 
|---|---|---|
| committer | Yannick Loriot <yannick.loriot@gmail.com> | 2013-08-13 16:58:13 +0200 | 
| commit | 0932765947b14407aa41fbe7ded00ca37a25f5c6 (patch) | |
| tree | fb25e237d9a5f62e4fc0bf274e6f7c16802692d7 /objective-c.html.markdown | |
| parent | 664d592bc79c7dcc6c429bcee79965ef3df464f5 (diff) | |
[NEW] Protocol Implementation
Diffstat (limited to 'objective-c.html.markdown')
| -rw-r--r-- | objective-c.html.markdown | 34 | 
1 files changed, 29 insertions, 5 deletions
| diff --git a/objective-c.html.markdown b/objective-c.html.markdown index 9d1178e1..187ea30a 100644 --- a/objective-c.html.markdown +++ b/objective-c.html.markdown @@ -215,20 +215,22 @@ int main (int argc, const char * argv[])  // Declare your class in a header(MyClass.h) file:  // Class Declaration Syntax: -// @interface <class name> : <parent classname> +// @interface ClassName : ParentClassName <ImplementedProtocols>  // {  //    Member variable declarations;  // }  // -/+ (type) Method declarations;  // @end -@interface MyClass : NSObject +@interface MyClass : NSObject <MyCustomProtocol>  {      int count;      id data;      NSString *name;  } -// Create the public getter/setter for the variable count -@property(assign) int count; +// Convenience notation to auto generate public getter and setter +@property int count; +@property (copy) NSString *name; // Copy the object during assignment. +@property (readonly) id data;    // Declare only a getter method.  // Methods  +/- (return type)methodSignature:(Parameter Type *)parameterName; @@ -246,8 +248,13 @@ int main (int argc, const char * argv[])  @implementation UserObject +// Call when the object is releasing +- (void)dealloc +{ +} +  // Constructors are a way of creating classes -// This is a default constructor +// This is a default constructor which is call when the object is creating  - (id)init  {      if ((self = [super init])) @@ -272,8 +279,25 @@ int main (int argc, const char * argv[])      return @42;  } +// Methods declared into MyProtocol +- (void)myProtocolMethod +{ +    // statements +} +  @end +/* + * A protocol declares methods that can be implemented by any class. + * Protocols are not classes themselves. They simply define an interface + * that other objects are responsible for implementing. + * / +@protocol MyProtocol +    - (void)myProtocolMethod; +@end + + +  ```  ## Further Reading | 
