【发布时间】:2010-11-25 12:07:48
【问题描述】:
我很难弄清楚如何获取使用 Xcode 创建的属性列表文件。我使用带有NSString 成员的数组创建了一个属性列表文件。我想获取该文件并获取所有NSString 成员并将其保存到UITextField。但我的问题是我看不到那个文件。不知道是不是找错了路径,还是不知道属性文件保存在哪里。
【问题讨论】:
标签: iphone xcode properties
我很难弄清楚如何获取使用 Xcode 创建的属性列表文件。我使用带有NSString 成员的数组创建了一个属性列表文件。我想获取该文件并获取所有NSString 成员并将其保存到UITextField。但我的问题是我看不到那个文件。不知道是不是找错了路径,还是不知道属性文件保存在哪里。
【问题讨论】:
标签: iphone xcode properties
如果文件是通过 Xcode 添加的,则该文件很可能在您的包中。要打开它,请使用:
NSDictionary *plist = [NSDictionary arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NameOfFile" ofType:@"plist"]];
在模拟器中运行它,然后在 Finder 中的 Library/Application Support/iPhone Simulator/Applications/... 中查看是否可以找到该文件,将其打开并仔细检查以确保添加了 Xcode文件。
在您的 Documents 文件夹中制作副本:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"My.plist"];
if (![plist writeToFile:path atomically:YES])
NSLog(@"not successful in writing the high scores");
【讨论】: