Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(1) Try using</p> <pre><code>NSLog(@"%@", imgurl); </code></pre> <p>The 1st argument of NSLog is always interpreted as a format string, even if it's a variable (the runtime doesn't care). If <code>imgurl</code> contains format specifiers (e.g. <code>%2c</code>) then something undefined may happen.</p> <hr> <p>(2) </p> <pre><code> galleryArray = [[NSMutableArray alloc] init]; galleryArray = [resultDictionary valueForKey:@"gallery"]; imgurl = (NSString *)[galleryArray objectAtIndex:0]; NSLog(@" -&gt; %@", galleryArray); NSLog(imgurl); </code></pre> <p>There are 2 problems here. The 2nd line will override the empty mutable array initialized in the 1st line, thus causing a memory leak. The <code>galleryArray</code> assigned in the 2nd line will likely be released after the function ends, thus creating a dangling pointer. The same goes for <code>imgurl</code>. This probably is the main cause of the crash. I recommend you read the <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/Articles/mmRules.html" rel="nofollow noreferrer">Cocoa Memory Management Rules</a> again. Anyway, this piece of code should be like:</p> <pre><code> self.galleryArray = [resultDictionary valueForKey:@"gallery"]; self.imgurl = [galleryArray objectAtIndex:0]; NSLog(@" -&gt; %@", galleryArray); NSLog(@"%@", imgurl); </code></pre> <p>or</p> <pre><code> [galleryArray release]; galleryArray = [[resultDictionary valueForKey:@"gallery"] retain]; [imgurl release]; imgurl = [[galleryArray objectAtIndex:0] retain]; // or -copy. NSLog(@" -&gt; %@", galleryArray); NSLog(@"%@", imgurl); </code></pre>
 

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