Search code examples
ioscustom-controlsreleasenskeyedarchiver

ios NSKeyedArchiver releasing = bad access


I have an noob problem and I would like you yo point me in the right direction. Basicly I have a custom class which implements the copying protocol. However when I save the class during execution the custom class i released and I get a bad access. I can see in instruments that the retain count is -2. I save the custom class with the following method:

-(void)storeDataInFile:(NSString*)dataFileName DataArray:(NSArray*)dataToStore 
{
    //Get the path
    NSString *path = [self pathToDocumentsForDataFile:dataFileName];
    //Archive the file
    [NSKeyedArchiver archiveRootObject:dataToStore toFile:path];
}

Is I use the method sor saving a array with strings it works flawless. What should I look deeper into regarding my custom class?

Regards


Solution

  • I soved this issue, however I only provided the solution in a comment which apprantly has been deleted. So I just wanted to post the answer which indicates it was a noob mistake. From an eralier test implementation I had the following method in the class

        - (id)copyWithZone:(NSZone *)zone
    {
        return self;
    }
    
    //retain is counted up
    - (id)retain {
        return self;
    }
    
    - (unsigned)retainCount {
        return UINT_MAX;
    }
    

    These methods ruined my retain count :)