Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This line:</p> <pre><code>self = [unarchiver decodeObjectForKey:kDateDataKey]; </code></pre> <p>is going to give you problems.</p> <p>What you're doing is to allocate a DateTracker object (<code>[DateTracker alloc]</code>), then create a new DateTracker object (by <code>-decodeObjectForKey:</code>) and make the "self" pointer refer to the new object. There are two problems with that:</p> <ul> <li>you no longer have a reference to the old object, so it's leaked</li> <li>the new object is not retained, so it goes away (or causes a crash if you try to release it)</li> </ul> <p>I would say the approach of having an object replace itself is a bit suspect. Perhaps you would do better to move the <code>filePath</code> variable outside of the <code>DateTracker</code> object, and unarchive it by something like:</p> <pre><code>DateTracker *currentTracker = [[DateTracker unarchiveFromFile:filePath] retain]; </code></pre> <p>where <code>unarchiveFromFile:</code> is a class method that does essentially what <code>initFromFile</code> did, without messing with <code>self</code>:</p> <pre><code>+ (DateTracker*)unarchiveFromFile:(NSString *)filePath { DateTracker *result = nil; if ([[NSFileManager defaultManager] attributesOfFileSystemForPath:filePath error:NULL]) { NSData *data = [[NSMutableData alloc] initWithContentsOfFile:filePath]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; result = [unarchiver decodeObjectForKey:kDateDataKey]; [unarchiver finishDecoding]; [unarchiver release]; [data release]; } return result; } </code></pre>
    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. 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