I am implementing a login system that uses the NSNotifications
userInfo
dictionary to pass login info by notification. The dictionary gets passed ok but when I try to convert one of the NSStrings
in the dictionary into an int using IntValue I get error. Even when I copy the dictionary object to another string I get the same error, but with a normal string there are no errors. Code:
- (void)loginComplete:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"Login Complete"]) {
NSDictionary *loginInfo = [notification userInfo];
loginString = [loginInfo objectForKey:@"login_string"];
NSLog(@"%@", loginString);
NSString* expString = [NSString stringWithString:[loginInfo objectForKey:@"expires_in"]];
// [loginInfo objectForKey:@"expires_in"] == @"604700"
expiresIn = [expString intValue];
NSLog(@"expiresIn: %i", expiresIn);
NSString * toInt = @"112345";
int realInt = [toInt intValue];
NSLog(@"realInt: %i", realInt);
}
}
So the first NSLog
provides correct info, and the conversion in the end (test) also works, but the expiresIn results in an error:
2015-01-13 17:53:06.976 API_test_osx[2867:143430] -[__NSArrayM length]: unrecognized selector sent to instance 0x600000441d40
2015-01-13 17:53:06.976 API_test_osx[2867:143430] *** WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <NSInvalidArgumentException> -[__NSArrayM length]: unrecognized selector sent to instance 0x600000441d40
If I try not to convert to int, the value can be logged just fine as a NSString
. What am I doing wrong?