Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As Peter says above, when you retrieve an object from an <code>NSArray</code> it is just a pointer to an object, regardless of what you cast it to. You could investigate this in various ways. look at where the array contents is being set and check what you are adding, it might be possible an <code>NSDictionary</code> has been mis-cast further up the chain. Also try setting a breakpoint before the array is read, and type into the debugger <code>po insights</code>. This will print the contents of the object. After the crash, you can also investigate the object that has caused the problem by doing a <code>po &lt;memory address&gt;</code>, in this case <code>po 0x99f60b0</code>.</p> <p>A good way to safeguard against this kind of thing is with introspection (although this wont solve the problem if you've got the wrong object in your array, but will stop the crash.) as so:</p> <pre><code>if ([strData isKindOfClass:[NSString class]]) { NSString *strReplace = [NSString stringWithFormat:@"%@",[strData stringByReplacingOccurrencesOfString:@"%20" withString:@" "]]; } </code></pre> <p>I can't see any errors in the code you posted up, although a couple of things I noticed. You don't need to check if <code>single == nil</code>. It is not possible to have <code>nil</code> in an <code>NSArray</code>.</p> <p>Also you are doing quite a lot of reassignment of pointers, and also trying to edit the contents of the array while looping through the array. This is not such a good idea in Objective-C. I've tested it and it seems to work in this case, but it's generally a good idea to create a new string pointer if you're creating a new string, to ensure the memory used by the old string is released correctly. Don't get me wrong the code works, but this kind of thing can pretty quickly lead to memory leaks that are difficult to track down later, just best practice stuff.</p> <p>In regards to the crash, I can't see that error message getting generated from that method, and where does the original code you posted fit into the extra code you posted? Please update your question with more details </p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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