2010-02-02 87 views
2

我想设置一个方法,在给定的文件路径上创建.plist文件,但是我当前的代码只能用于修改plist。有没有简单的方法来创建plist文件?这只是该方法的初稿,最终版本将为course_title带来一个变量。由于创建一个plist iPhone SDK

- (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

回答

3

你只是初始化使用

NSMutableDictionary* plistDict = [NSMutableDictionary dictionary]; 

,而不是从文件中读取一个空的字典。然后你继续进行。

+0

非常感谢你 - 回头看我不知道我怎么没有意识到这一点。干杯 – Jack 2010-02-02 21:57:17