Coasty
Coasty

Reputation: 49

NSURL Exceptions

I am trying to grab a path value from an array for an NSURL to set an icon in my app. I get an

NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x5622590.

If I use an nslog I get the expected output:

NSLog(@"%@",[[wforecast.wicons objectAtIndex:0]valueForKey:@"nodeContent"]);

Which gives me:

enter image description here

Im setting the value as follows

NSURL *urlpath;

NSString *urls = [[wforecast.wicons objectAtIndex:0] valueForKey:@"nodeContent"];

urlpath = [NSURL URLWithString:(NSString *)urls];

I appreciate this is a longwinded way of doing things but I was trying to break up the individual components to find out what was going wrong but I am at a loss!

Upvotes: 2

Views: 3140

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96323

You have essentially the same problem as this other questioner had. You passed an object that is not an NSString where you needed to pass an NSString.

Use the debugger to determine exactly where the exception occurred. If you haven't done this, I wouldn't be so sure that the code you showed is what caused it; the debugger will tell you where the exception occurred with no room for doubt.

Once you've found where the exception occurred, you can examine the object that you passed, and look back at where you got it from. You need to fix either how you retrieve the string or how you stored it in the place you're now getting it from.

Upvotes: 6

Related Questions