설정 'NSInteger'잘못된 수신기 종류 나 간단한 클래스의 내 구현이 라인에 오류 "잘못된 수신기 종류 'NSInteger'을"얻을 NSInteger 속성
self.price = p; // this line throws error
것은 내가 copy
으로 가격을 지정해야 하는가 ? 자세한 내용 :
헤더 파일 :
@interface SafeItem : NSObject {
NSString *name;
NSInteger price;
NSString *category;
NSInteger itemid;
BOOL hasImage;
}
@property (nonatomic,copy) NSString *name;
@property (nonatomic) NSInteger price;
@property (nonatomic,copy) NSString *category;
@property NSInteger itemid;
@property BOOL hasImage;
- (id)initWithName:(NSString*) n price:(NSInteger) p category:(NSString*) c;
@end
구현 :
@implementation SafeItem
@synthesize name, price, category, itemid, hasImage;
- (id)initWithName:(NSString*) n price:(NSInteger) p category:(NSString*) c {
if(self=[super init]){
self.itemid = [SafeItem getNextId];
self.name = [n copy];
self.price = p; // this line throws error
self.category = [c copy];
}
return self;
}
감사합니다. 나는 코드의 다른 부분에 뭔가 잘못된 것이 있다고 생각한다. (분명히 setter를 명시 적으로 구현 한 것은 아니지만). 그건 그렇고, 미래의 독자를 위해 : "self"와 "copy"(예 : "name = n"; "self.name = n"또는 "name = [n copy" 전자). 이 페이지에서 여러 가지 제안을 시도 할 때 둘 다 제거하고 나중에 문자열에 액세스하려고 할 때 EXC_BAD_ACCESS로 끝납니다. – unsorted