내가 본 카테고리의 모든 예는 사용자 정의 클래스보다는 일부 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
그리고 범주 정의 :
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
이 있습니까 :
@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
이 다음 오류 및 경고를 줄 것이다 이 일을하는 방법?
>> 여기서 문제 << 확인 : 주석 다음
는,이 코드를 다시 작성하는 방법 중 하나입니다.. 제 예제를 수정할 수 있습니까? – 4thSpace