I'm working on a Facebook Feed App for the iPhone that, among other things, determines if a picture is attached to a post, and stores it in an array. When I run the code, my NSLogs tell me that nothing is being put into the array, even though it's reading whether or not there is an objectAtKey:@"picture". The following is some of my code.
from MasterView.m:
//create array containing individual "datas"
NSArray *items = [json objectForKey:@"data"];
for(NSDictionary *item in items)
{
// store message in ItemStore sharedStore
if([item objectForKey:@"message"] || [item objectForKey:@"message"] != nil ||
[[item objectForKey:@"message"] length] > 0){
[[JSONFeedItemStore sharedStore] createItem:[item objectForKey:@"message"]];
}
//
if([item objectForKey:@"picture"]){
[[JSONFeedItemStore sharedStore] createPicture:[[item objectForKey:@"picture"] description]];
NSLog(@"url: %@", [item objectForKey:@"picture"]);
} else {
[[JSONFeedItemStore sharedStore] createPicture:@"http://i.imgur.com/TpIK5.png"]; // blank
NSLog(@"creating blank picture");
}
}
from ItemStore.m
- (void)createPicture:(NSString *)pictureUrl
{
[pictures addObject:pictureUrl];
NSLog(@"Number: %d, URL: %@", [pictures count], [pictures objectAtIndex:[pictures count]]);
}
and my console
2012-08-07 08:21:54.153 JSONFeed[2502:f803] Number: 0, URL: (null)
2012-08-07 08:21:54.154 JSONFeed[2502:f803] creating blank picture
2012-08-07 08:21:54.155 JSONFeed[2502:f803] Number: 0, URL: (null)
2012-08-07 08:21:54.156 JSONFeed[2502:f803] creating blank picture
2012-08-07 08:21:54.157 JSONFeed[2502:f803] Number: 0, URL: (null)
2012-08-07 08:21:54.157 JSONFeed[2502:f803] url: http://photos-a.ak.fbcdn.net/hphotos-ak-ash4/423482_427478620624383_82270372_s.jpg
2012-08-07 08:21:54.158 JSONFeed[2502:f803] Number: 0, URL: (null)
2012-08-07 08:21:54.158 JSONFeed[2502:f803] creating blank picture
SharedStore is a part of an ItemStore class created to store the messages and pictures from Facebook posts. If you have any questions, or need to see more code, feel free to ask. I'm also taking any suggestions for improvements, as I am still new to programming Apps.
createPicturewhy are you sending it[[item objectForKey:@"picture"] description]instead of just[item objectForKey:@"picture"]?description?