私が見たカテゴリの例はすべて、カスタムクラスではなくObjective-Cクラスを使用しています。たとえば、NSMutableArray、NSArray、NSStringなどです。カスタムクラスのカテゴリを作成したいと思います。ここで私はちょうどテストするために作成された役に立たない例だが、コンパイルに失敗:カテゴリはObjective-Cクラスでのみ作成できますか?
//person.h
@interface Person (aCategory) : NSObject {
NSString *MyName;
NSString *webAddress;
}
@property(nonatomic, retain) NSString *MyName;
@end
//person.m
#import "Person+aCategory.h"
@implementation Person
@synthesize MyName;
@end
そしてカテゴリ定義:
@interface aCategory : NSObject {
NSString *webAddress;
}
@property(nonatomic, retain) NSString *webAddress;
- (void)changeWebAddress;
@end
//in aCategory.h
#import "aCategory.h"
@implementation aCategory
@synthesize webAddress;
- (void) changeWebAddress{
self.webAddress = @"http://www.abc.com";
}
@end
これは、次のエラーや警告を与える:
error: Person+aCategory.h: no such file or directory
warning: cannot find interface declaration for Person
error: no declaration of property 'MyName' found in interface
がありますこれを行う方法?
>>ここでの問題は、あなたが書いたことは、遠隔カテゴリを定義するための正しい方法ではないということです<< [OK]をクリックします。。私の例を修正できますか? – 4thSpace