Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When an object seems to change class, it's almost always because it has been deallocated, and another object is now residing on the same memory location. All object variables are actually <em>pointers</em> to memory locations (that's what the * means), and unlike in many other languages you have to always remember that you're working with memory locations. (Well, not always, once you get the hang of it. But definitely when you're debugging.)</p> <p>To debug these problems, it can be very useful to use <code>NSZombie</code>. Just search SO or the web for info.</p> <blockquote> <p>then in .m file I synthesize it: <code>curTitle = [[NSString alloc] init];</code></p> </blockquote> <p>This is <strong>not</strong> synthesizing. What you are doing here is merely assigning a value to the variable. More precisely, you create an object somewhere in memory (alloc) and initialize it (init) and then you set the value of <code>curTitle</code> to point to that memory location.</p> <p><em>There is no need for you to have this line in your code at all.</em></p> <p><code>curTitle = string;</code></p> <p>Here you are <em>overwriting</em> the old value of <code>curTitle</code> with a pointer to <em>another</em> string. Your problem is most likely that that other string later gets deallocated, and the memory location gets reused to hold another object (a dictionary in this case). (If you don't know about the retain/release mechanisms, you need to read up on those to understand what happens.)</p> <p><code>slide.title = curTitle;</code></p> <p>Since <code>curTitle</code> is pointing to a memory location that has been re-used to hold a random object (or even worse: garbage) this line will fail. In fact, you're lucky that it fails, because if it didn't (if the location hadn't been reused yet) it would be even harder to detect the bug.</p> <p>What you should do is to declare a property, then synthesize it and <strong>access the variable through the property</strong>:</p> <p><code>self.curTitle = aString;</code></p> <p>This will make sure that you actually copy and take ownership of the string so that even if the original string is released, you will still have a valid copy.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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