创建一个plist iPhone SDK

时间:2010-02-02 19:27:02

标签: iphone plist

我正在尝试设置一个在给定文件路径下创建.plist文件的方法,但是我当前的代码仅适用于修改plist。有没有一种简单的方法来创建plist文件?这只是方法的初稿,最终版本将为course_title采用变量。感谢

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

感谢代码转到http://www.ipodtouchfans.com/forums/showthread.php?t=64679

1 个答案:

答案 0 :(得分:3)

您只需使用

初始化一个空字典
NSMutableDictionary* plistDict = [NSMutableDictionary dictionary];

而不是从文件中读取它。然后你像以前一样继续。