IOS开发中的分類和擴展的使用

如下代码:

@interface PhoneGapDelegate (Private)
+ (NSString*) startPage;
- (NSArray*) praseInterface: (NSArray*) xxxx;
@end

知识点1:
参考网址:
http://stackoverflow.com/questions/360968/category-usage-in-objective-c
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1

A category allows you to add methods to an existing class—even to one for which you do not have the source. Categories are a powerful feature that allows you to extend the functionality of existing classes without subclassing. Using categories, you can also distribute the implementation of your own classes among several files.

Class extensions are similar, but allow additional required APIs to be declared for a class in locations other than within the primary class @interface block.
Adding Methods to Classes

目前一版不在后面添加具体分类,而是使用()
如下:

// someClass.m
@interface someClass ()
-(void)extend;
@end

@implementation someClass
    // all the methods declared in the .h file and any superclass
    // overrides in this block
    // Implement private methods in this block as well.
-(void)extend {
    // implement private method here;
}

@end

知识点2
参考网址:http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectivec/chapters/ocDefiningClasses.html
Methods and properties for the class are declared next, before the end of the class declaration. The names of methods that can be used by class objects, class methods, are preceded by a plus sign。
加号的作用理解为可以直接通过类进行调用:

[[self.class] startPage]
posted @ 2012-11-13 13:55  日光之下无新事  阅读(117)  评论(0编辑  收藏  举报