문제

I'm trying to create an Objective-C class. When I use the -setValue: method, the program crashes at that line. Here is the code: HugeNumber.h :

#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 = @"0123456789abcdefghijklmnepqrstuvwxyz";
@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;
}

The error log I get is :

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

Why does the program crashes? What am I doing wrong?

도움이 되었습니까?

해결책

You have missed setValueInString: method definition in .m file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top