2013-02-13 1 views
0

Objective-C 클래스를 만들려고합니다. -setValue: 메서드를 사용하면 해당 줄에서 프로그램이 충돌합니다. 여기 코드는 다음과 같습니다 HugeNumber.h :키 값 코딩 크래시 - Objective-C

#import <Foundation/Foundation.h> 

@interface HugeNumber : NSObject{ 

NSString *value; 
NSMutableArray *charSetArray; 
} 

-(void)setValueInString:(NSString *)string; 
-(NSString *)valueInString; 
-(int)valueInInt; 
-(NSString *)decimalValueInString; 
-(void)setDecimalValueInString; 
@end 

HugeNumber.m :

#import "HugeNumber.h" 
const NSString* charSet = @"abcdefghijklmnepqrstuvwxyz"; 
@implementation HugeNumber 

- (id)init{ 
self = [super init]; 
if (self){ 
    for (int i = 0; i < [charSet length]; i++){ 
     NSString* str = [NSString stringWithFormat:@"%hu",[charSet characterAtIndex:i]]; 
     [charSetArray addObject:str]; 
    } 
} 
return self; 
} 

-(void)setValue:(NSString *)string{ 
value = string; 
} 

@end 

main.m :

#import <Foundation/Foundation.h> 
#import "HugeNumber.h" 

int main(int argc, const char * argv[]) 
{ 

@autoreleasepool { 

    HugeNumber *number = [[HugeNumber alloc] init]; 
    NSString *string = @"11"; 
    [number setValueInString:string]; 
    NSLog(@"%i",[number valueInInt]); 

} 
return 0; 
} 

내가 오류 로그는 다음과 같습니다

2013-02-13 17:56:43.303 Huge Numb Test[7442:303] -[HugeNumber setValueInString:]: unrecognized selector sent to instance 0x10010a620 
2013-02-13 17:56:43.306 Huge Numb Test[7442:303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HugeNumber setValueInString:]: unrecognized selector sent to instance 0x10010a620' 
*** First throw call stack: 
(
0 CoreFoundation      0x00007fff8a15b0a6 __exceptionPreprocess + 198 
1 libobjc.A.dylib      0x00007fff90c5e3f0 objc_exception_throw + 43 
2 CoreFoundation      0x00007fff8a1f16ea -[NSObject(NSObject) doesNotRecognizeSelector:] + 186 
3 CoreFoundation      0x00007fff8a1495ce ___forwarding___ + 414 
4 CoreFoundation      0x00007fff8a1493b8 _CF_forwarding_prep_0 + 232 
5 Huge Numb Test      0x00000001000018a1 main + 129 
6 libdyld.dylib      0x00007fff8cfa17e1 start + 0 
7 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminate called throwing an exception 

왜 프로그램이 충돌합니까? 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

1

.m 파일에 setValueInString: 메서드 정의가 누락되었습니다.

관련 문제