Search code examples
objective-cnsstringsigabrtnsscanner

Why am I receiving an error message when attempting NSScanner to use in a NSString statement?


I would like to know why I get an error message

Thread 1: Program received signal: "SIGABRT")

When I use this line of code:

NSScanner *userEntered = [[NSScanner alloc] scannerWithString:temp];

The error is:

2011-04-18 02:06:11.995 XXX[25929:207] -[NSConcreteScanner scannerWithString:]: unrecognized selector sent to instance 0x6816bc0
2011-04-18 02:06:11.999 XXX[25929:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteScanner scannerWithString:]: unrecognized selector sent to instance 0x6816bc0'

Thank you.


Solution

  • +scannerWithString is a class method and should be used the following way:

    NSScanner *userEntered = [NSScanner  scannerWithString:temp];