Category / Extensions / Protocol /Informal Protocol

来源:互联网 发布:软件评测师难考吗 编辑:程序博客网 时间:2024/06/02 05:36
nil      a null object pointer (id)0
Nil     a null class pointer   (Class)0
NO     a boolean false value  (BOOL)0
YES    a boolena true value  (BOOL)1

1. Category
   1.1 the declaration of a category interface looks very much like a class interface declarartion
        //"ClassName+CategoryName.h"
        #import "ClassName.h"
        
        @interface ClassName (CategoryName)
           //method declaration
        @end 
        --------------------------------
        //"ClassName+CategoryName.m"
        #import "ClassName+CategoryName.h"
        
        @implementation ClassName (CategoryName)
         //method definitions
        @end

2.  Extensions
   2.1  extensions is just like inhrite

3. Protocal 
   3.1 protocol use for declaring interface for others to implement
   3.2 delcaring a protocol (Formal protocols)
         @protocol MyXMLSupport
             //method declarations
            -(NSXIMLElemtn *)XMLRepresentation;
            -initFromXMLRepresentation:(NSXMLElement *)XMLElement;
         @end
         ----------------------------------
         @protocol MyXMLSupport
            @optional
              -(void)showText;
            @required
            //...
         @end
    3.4 informal protocols
        informal protocols are typically declared as categories of the NSObject class.
        @interface NSObject (MyXMLSupport)
           //method declaretion
        @end
   3.5 use the protocols
        @interface ClassName:ItsSuperClass <protocol list>
        @end
         
原创粉丝点击