So I have a username saved in the UserDefaults. For some reason, I am experiencing some strange behavior.
I have a data controller that goes and fetches some data from the server based on the user name.
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSLog(@"NSUserDefaults dump: %@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
userID = [prefs stringForKey:@"username"];
This works fine for the first few times, but after I do some random stuff and go back to try and reload the views, it crashes. It says:
-[CFString retain]: message sent to deallocated instance 0x4b18ff0
This is strange because it is stopping on the NSLog line. Has anyone seen this before or know why it may be happening??
How you defined your userID? If it’s a property with a retain attribute you should call
self.userID = [prefs stringForKey:@"username"];this way your string will be retained automatically. The string that is returned from stringForKey is autoreleased.