tags:

views:

716

answers:

1

Hi,

I am trying to set up a method that creates a .plist file at a given file path, however my current code only works for modifying a plist. Is there an easy way to create the plist file? This is simply a first draft of the method, the final version will take a variable for the course_title. Thanks

- (void)writeToPlist{
    NSString *filePath = [NSString stringWithFormat:@"%@/course_title", DOCUMENTS_FOLDER];
    NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

    [plistDict setValue:@"1.1.1" forKey:@"ProductVersion"];
    [plistDict writeToFile:filePath atomically: YES];    
}

Thanks for the code goes to http://www.ipodtouchfans.com/forums/showthread.php?t=64679

+1  A: 

You just init an empty dictionary using

NSMutableDictionary* plistDict = [NSMutableDictionary dictionary];

instead of reading it from the file. Then you proceed as before.

Nikolai Ruhe
Thank you so much - looking back I don't know how I didn't realise that. Cheers
Jack