• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Save dictionary to local file please help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Save dictionary to local file please help!


  • Subject: Save dictionary to local file please help!
  • From: Ben Spam <email@hidden>
  • Date: Mon, 11 May 2009 09:10:10 +0000 (GMT)

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Save dictionary to local file please help!
      • From: Michael Vannorsdel <email@hidden>
    • Re: Save dictionary to local file please help!
      • From: Graham Cox <email@hidden>
  • Prev by Date: IKImageBrowserView is not reloading data.
  • Next by Date: Creating an NSInvocation from an NSMethodSignature
  • Previous by thread: Re: IKImageBrowserView is not reloading data.
  • Next by thread: Re: Save dictionary to local file please help!
  • Index(es):
    • Date
    • Thread