Read a String Back From NSUserDefaults?

Brad Carter bcarter at mac.com
Mon Feb 12 22:26:16 PST 2007


I'm learning NSUserDefaults and have run into a snag.  I can  
successfully save an NSTextField into NSUserDefaults by using the  
following:

[[NSUserDefaults standardUserDefaults] setObject: 
[box2IPAddressTextField stringValue] forKey:BCBox2IPAddress];

I can open up the plist file in the preferences folder and see the  
value (an IP address) for the key BCBox1IPAddress and it's Class is  
String.  When I read the value back and try to store it to a string  
using the following:

box2IPAddress = [[NSUserDefaults standardUserDefaults]  
objectForKey:BCBox2IPAddress];

I get the following error when my method runs. By the way,  
box2IPAddress is an NSString.

-[NSCFString substringFromIndex:] called with out-of-bounds index.  
For apps linked on Tiger this will raise an exception. For earlier  
apps it will produce this one-time warning and continue with existing  
behavior (which is undefined).

Any ideas?

Thanks,

Brad


More information about the MacOSX-dev mailing list