私はiPhone開発を勉強しており、読み書きplistファイルの問題に直面しています。私はiPhone開発の本の例に従ったが、実行中にエラーメッセージが表示され続ける。iPhone iOS 5の読み書きplier
エラーメッセージは言う:2012-04-26 00:21:09.759 FileHandling [5915:207] - [__ NSCFDictionaryのaddObjectは:]:認識されないセレクターここインスタンスに0x685ac40
を送信したサンプルコードは、(それはそうです...私には罰金が):
NSString *plistFileName = [[self documentPath] stringByAppendingPathComponent: @"Apps.plist"];
NSLog(@"Where is the file? => %@", plistFileName);
if ([[NSFileManager defaultManager] fileExistsAtPath:plistFileName]) {
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistFileName];
for (NSString *category in dict) {
NSLog(@"%@", category);
NSLog(@"=========");
NSArray *titles = [dict valueForKey:category];
for (NSString *title in titles) {
NSLog(@"%@", title);
}
}
} else {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Apps" ofType: @"plist"];
NSLog(@"%@", plistPath);
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile: plistPath];
NSLog(@"Let's take a look : %@", dict);
NSMutableDictionary *copyOfDict = [dict mutableCopy];
NSLog(@"Let's look at the mutable dictationary : %@", copyOfDict);
NSArray *categoriesArray = [[copyOfDict allKeys] sortedArrayUsingSelector: @selector(compare:)];
for (NSString *cateogry in categoriesArray) {
NSArray *titles = [dict valueForKey: cateogry];
NSMutableArray *mutableTitles = [titles mutableCopy];
[mutableTitles addObject: @"New App Title"];
[copyOfDict setObject: mutableTitles forKey:cateogry];
}
NSString *fileName = [[self documentPath] stringByAppendingPathComponent: @"Apps.plist"];
[copyOfDict writeToFile: fileName atomically:YES];
}