2013-02-13 1 views
0

J'essaie de créer une classe Objective-C. Lorsque j'utilise la méthode -setValue:, le programme se bloque à cette ligne. Voici le code: HugeNumber.h:Erreur de codage de valeur-clé - 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; 
} 

Le journal des erreurs que je reçois est:

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 

Pourquoi le programme plante-t-il? Qu'est-ce que je fais mal?

Répondre

1

Vous avez manqué la définition de la méthode setValueInString: dans le fichier .m.