I am currently beginning writing some unit test in my project. However, seems that I met some issue:
- (void)testThatItIsValidNumber
{
BOOL result1 = [NSString isValidNumber:@"1234567890987654"];
BOOL result2 = [NSString isValidNumber:@" ^123dadaj"];
BOOL result3 = [NSString isValidNumber:@"123 09 123"];
BOOL result4 = [NSString isValidNumber:@"~#)(^%@*#&Bhadahj1@"];
XCTAssertFalse(result1);
XCTAssert(result2);
XCTAssertFalse(result3);
XCTAssert(result4);
}
This gave me an error:
caught "NSInvalidArgumentException", "+[NSString isValidNumber]: unrecognized selector sent to class 0x1069448e0"
Any one can guide me to the right way?
Edit:
+ (BOOL)isValidNumber:(NSString *)value {
const char *cvalue = [value UTF8String];
unsigned long len = strlen(cvalue);
for (int i = 0; i < len; i++) {
if(!isNumber(cvalue[i])){
return FALSE;
}
}
return TRUE;
}
Aucun commentaire:
Enregistrer un commentaire