Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS NSXML dictionary not adding to array
    primarykey
    data
    text
    <p>I have an instance of the NSXML Parser parsing some xml and storing it in an array of objects. The XML has some image URLS and titles that I am trying to add to a dictionary, and then add the dictionary to an array in the data object. The dictionary is being set properly but it won't add to the array. Below is the xml and code:</p> <p>XML:</p> <p><a href="http://www.flashalert.net/rss.html?id=3753" rel="nofollow">http://www.flashalert.net/rss.html?id=3753</a></p> <p>Code:</p> <pre><code>- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { NSString *string1 = [string stringByReplacingOccurrencesOfString:@"amp;" withString:@""]; NSString *string2 = [string1 stringByReplacingOccurrencesOfString:@"&amp;quot;" withString:@"\""]; currentNodeContent = (NSMutableString *) [string2 stringByStrippingHTML]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ([elementname isEqualToString:@"item"]) { isStatus = YES; currentPressRelease = [FCPressRelease alloc]; } if ([elementname isEqualToString:@"media:content"]) { isMedia = YES; media = [[NSMutableDictionary alloc] init]; [media setValue:[attributeDict valueForKey:@"url"] forKey:@"url"]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if (isStatus) { if ([elementname isEqualToString:@"pubDate"]) { currentPressRelease.pubDate = currentNodeContent; } if ([elementname isEqualToString:@"title"]) { currentPressRelease.title = currentNodeContent; } if ([elementname isEqualToString:@"description"]) { currentPressRelease.summary = currentNodeContent; } if ([elementname isEqualToString:@"guid"]) { currentPressRelease.guid = currentNodeContent; } } if (isMedia) { if ([elementname isEqualToString:@"media:title"]) { [media setValue:currentNodeContent forKey:@"title"]; } } if ([elementname isEqualToString:@"media:content"]) { [currentPressRelease.images addObject:media]; media = nil; } if ([elementname isEqualToString:@"item"]) { if (currentPressRelease != nil) { [self.posts addObject:currentPressRelease]; currentPressRelease = nil; currentNodeContent = nil; } else { currentPressRelease = nil; currentNodeContent = nil; } } } </code></pre> <p>FCPressRelease.h</p> <pre><code>@interface FCPressRelease : NSObject @property (strong, nonatomic) NSString *pubDate; @property (strong, nonatomic) NSString *title; @property (strong, nonatomic) NSString *summary; @property (strong, nonatomic) NSString *guid; @property (strong, nonatomic) NSMutableArray *images; @end </code></pre> <p>FCPressRelease.m</p> <pre><code>@implementation FCPressRelease @synthesize pubDate = _pubDate; @synthesize title = _title; @synthesize summary = _summary; @synthesize guid = _guid; @synthesize images = _images; @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload