views:

67

answers:

3

hello all, can any one help me with this how to write a NSMutableDictionary into a plist....

thanks in advance..

+1  A: 
[yourDict writeToFile:filePath atomically:YES];

Note that dictionary must contain plist objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary). And dictionary keys must be NSString objects

Vladimir
but it doesnt work..
apple
here's my code [nameDetails writeToFile:loginDetails atomically:YES];
apple
What is loginDetails path? And are you sure that your dictionary conforms the conditions for its contents types?
Vladimir
+1  A: 

Make sure the pList file you are writing to is located in a legal place to edit it, for example Documents in the apps sandbox. Then find the path to that location (if there is an existing pList file, it will overwrite), and use:

[myDictionary writeToFile:path atomically:YES];

Write how far you are in the process, and maybe some code / error-message...

John Kofod
here's my code: NSMutableDictionary *nameDetails=[[NSMutableDictionary alloc] init]; [nameDetails setValue:username forKey:USERNAME_KEY]; [nameDetails setValue:password forKey:PASSWORD_KEY]; NSString *loginDetails = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"plist"]; [nameDetails writeToFile:loginDetails atomically:YES]; savedStock = [NSMutableDictionary dictionaryWithContentsOfFile:loginDetails];
apple
A: 

NSMutableDictionary *nameDetails=[[NSMutableDictionary alloc] init]; [nameDetails setValue:username forKey:USERNAME_KEY]; [nameDetails setValue:password forKey:PASSWORD_KEY];

NSString *loginDetails = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"plist"];

[nameDetails writeToFile:loginDetails atomically:YES]; savedStock = [NSMutableDictionary dictionaryWithContentsOfFile:loginDetails];

apple