• 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
Re: Save dictionary to local file please help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Save dictionary to local file please help!


  • Subject: Re: Save dictionary to local file please help!
  • From: Michael Vannorsdel <email@hidden>
  • Date: Tue, 12 May 2009 02:55:42 -0600

You need to retain destinationPath when you create it so it doesn't go away. You properly retain dataDict, now do the same with destinationPath and you should be ok. Also you don't need to retain newRecord; the dictionary will retain it when you add it.


On May 11, 2009, at 3:10 AM, Ben Spam wrote:

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];

}

_______________________________________________

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: Graham Cox <email@hidden>
References: 
 >Save dictionary to local file please help! (From: Ben Spam <email@hidden>)

  • Prev by Date: Re: IKImageBrowserView is not reloading data.
  • Next by Date: Search menu item not appearing in Help menu in some locales
  • Previous by thread: Re: Save dictionary to local file please help!
  • Next by thread: Re: Save dictionary to local file please help!
  • Index(es):
    • Date
    • Thread