Note that there are some explanatory texts on larger screens.

plurals
  1. POstring converted to NSURL and stored as property successful, later returns nil
    text
    copied!<p>I am parsing strings from a feed, converting them to URL, and storing them as a property of FeedItem. Initially, they are successfully converted to URL and stored, but later, when I access the property, it is nil.</p> <p>FeedItem.h</p> <pre><code>@interface FeedItem : NSObject @property (nonatomic, strong) NSString* author; @property (nonatomic, strong) NSURL* imageURL; @property (nonatomic, strong) NSString* datePublished; @end </code></pre> <p>Parser.m</p> <pre><code>- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { // Custom blog object initialized here if ([elementName isEqualToString:@"entry"]) { self.blogEntry = [[FeedItem alloc] init]; } // Parse image URL that accompanies some blog entries self.blogEntry.imageURL = [NSURL URLWithString:[attributeDict objectForKey:@"url"]]; if ([[NSURL URLWithString:[attributeDict objectForKey:@"url"]] isKindOfClass:[NSURL class]]) { NSLog( @"converted to a url" ); if ([self.blogEntry.imageURL isKindOfClass:[NSURL class]]) { NSLog(@"property of object is url"); }else if (!self.blogEntry.imageURL) { NSLog(@"url becomes nil"); }else{ NSLog(@"property of object is NOT url"); } } } </code></pre> <p>This prints "converted to a url" and "property of object is url" every time it should. However, later in the same file:</p> <pre><code>- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"entry"]) { // An individual blog has been parsed and a pointer to it is added to the parsedResults array if ([self.blogEntry.imageURL isKindOfClass:[NSURL class]]) { NSLog( @"URL passed" ); }else if (!self.blogEntry.imageURL) { NSLog( @"is nil" ); }else{ NSLog(@"no luck"); } [self.parsedResults addObject:self.blogEntry]; } } </code></pre> <p>This prints "is nil" every time.</p> <p>Here is an example of one of the URLs being parsed: url='<a href="http://2.bp.blogspot.com/-HlNeYKf6Jyk/URKJ0NzA_kI/AAAAAAAAADY/AAkM6mNITlo/s72-c/Ananya&apos;s+Illustration.jpg" rel="nofollow">http://2.bp.blogspot.com/-HlNeYKf6Jyk/URKJ0NzA_kI/AAAAAAAAADY/AAkM6mNITlo/s72-c/Ananya&apos;s+Illustration.jpg</a>'</p> <p>I know there can be issues if a URL has a special character, but because it is successful at first, I figured this shouldn't be the issue.</p> <p>I'm new to objective-c...what am I missing??</p>
 

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