开发者

Subcategory of Category in Objective-C

My question is a simple fundamental question for creating a subcategory of a category in objective-c.

Consider a file named NSString+categoryName.h given as follows:

#import <Foundation/Foundation.h>

@interface NSString (categoryName)
...
@end

with a corresponding implementation file named categoryName.m (not shown).

How would I make a subcategory if this? Here is my initial thought (contained in a separate file called NSString+categoryName+subCategoryName.h):

//Should there be an import statement here to prepare compiler for appearance of categoryName?
#import <Foundation/Foundation.h>

@interface categoryName (subCategoryName)
...
@end

开发者_运维技巧possessing a separate implementation file of a similar name NSString+categoryName+subCategoryName.m:

// Is the import correct here?  Do I need to somehow reference this in my .h file?
#import "NSString+categoryName.h"

@implementation categoryName (subCategoryName)
...
@end

Any help with this matter is greatly appreciated, as always!


I have never heard of a "subcategory" in Obj-C. You can create as many categories as you like for the same class, and you can adopt a naming convention like @interface Class (category_subcategory) ... @end or similar, but your idea of making a category on a category does not seem workable.


Categories are not hierarchical in Objective-C. They're just a way to put methods into groups that aren't all loaded at once.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜