Read a String Back From NSUserDefaults?

Brad Carter bcarter at mac.com
Tue Feb 13 07:38:44 PST 2007


Below is the method I'm trying to restore this code from.  NSLog does  
print out the UserDefaults that were read in to box2IPAddress so my  
problem is getting the NSString ip to point to box2IPAddress.  In the  
case 2: statement if I make it like this, ip = @"box2IPAddress";  I  
get the same error and also get:

-[NSCFString substringFromIndex:]: Range or index out of bounds.

- (BOOL)setOutputNumber:(int)a to:(int)b usingBox:(int)c
{	
	NSString *ip;
	NSString *box2IPAddress = [[NSUserDefaults standardUserDefaults]  
objectForKey:BCBox2IPAddress];	
	
	NSLog (@"box2's ip address is: %@", box2IPAddress);  // This outputs  
fine.
	
	// Determine the IP of the box we want to talk to as passed with  
usingBox:(int)c
	switch ( c ) {
		case 1:
			ip = BOX1IP;  // BOX1IP is a define statement, was before I  
started to use preferences.
			break;
		case 2:
			ip = box2IPAddress;  // This is what's causing the above error
			break;
	}



On Feb 13, 2007, at 12:15 AM, Scott Stevenson wrote:

>
> On Feb 12, 2007, at 10:26 PM, Brad Carter wrote:
>
>> 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).
>
> I think there's probably some relevant code we're not seeing. It's  
> possible but unlikely that fetching the value alone would cause a  
> bounds exception. You would probably need to be processing it in  
> some way to cause this error.
>
> Can you post a simplified sample project which reproduces the problem?
>
>      - Scott
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev at omnigroup.com
> http://www.omnigroup.com/mailman/listinfo/macosx-dev




--------------------------------------------------------------
The smime.p7s file below is my public encryption key, not a virus.




More information about the MacOSX-dev mailing list