Please help me, I'm in serious trouble if I do not sort this out!

I am trying to save a dictionary to a local file, but inserting a new record 
crashes my app and I can not fathom why, here is my code...please let me know 
if you see anything im doing wrong..
PS: the random key is purely for testing.

#import "MyTestClass.h"


@implementation MyTestClass
- (id) init
{
    self = [super init]; 
    
    //get path
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
NSUserDomainMask, YES);
    destinationPath = [[paths objectAtIndex:0] 
stringByAppendingPathComponent:@"filePath.plist"];
    //
    dataDict = [NSMutableDictionary 
dictionaryWithContentsOfFile:destinationPath];
    
    if(!dataDict){ NSLog(@"No File"); dataDict = [[NSMutableDictionary alloc] 
init];} else{[dataDict retain];}
    return self;
}
- (void) insertNewRecord:(NSMutableDictionary*)newRecord{
    [newRecord retain];
    [dataDict setValue: newRecord forKey: [NSString stringWithFormat:@"test%d", 
(arc4random() % 1000)]  ];
 
    bool didSave = [dataDict writeToFile:destinationPath atomically:YES];

}


//singleton
static MyTestClass *myInstance = NULL;
+ (MyTestClass *)myTestClass
{
    @synchronized(self)
    {
        if (myInstance == NULL)
            myInstance = [[self alloc] init];
    }
    return(myInstance);
}

@end





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to