Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Incompatible pointer types sending NSArray to parameter of type NSString (JSON parsing)

Im working on an app using the Blog Reader App as a starting point. I'm trying to show an image and I got it to work but I get this error:

Incompatible pointer types sending NSArray to parameter of type NSString (JSON parsing)

I know its because my image property "thumb" is an Array and not a String, but I dont know how to change the code so the error could go away.

@property (nonatomic, strong) NSArray *thumb;

- (NSURL *) thumbURL {
    return [NSURL URLWithString: self.thumb]; (The error points to "self")
}

Thanks.

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

The first question is why is your thumb an NSArray and not an NSString? To change it all you have to change the class name from NSArray to NSString

@property (nonatomic, strong) NSString *thumb;

My thumb is an NSArray because of the way my JSON is set up, and I know thats the reason I get the warning. I just want change this code so I stop getting the warning.

- (NSURL *) thumbURL {
    return [NSURL URLWithString: self.thumb]; (The error points to "self")
}
Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

If it's an array of strings then you need to access the individual element within the array. You can access an element within the array using the method objectAtIndex. So you would access an element within your array: [self.thumb objectAtIndex:0]. If you want to know more about arrays then check out this video: http://teamtreehouse.com/library/ios-development/build-an-iphone-crystal-ball-app/learning-the-language/getting-to-know-arrays