どのように.... iphoneでplistファイルからの読み取りおよび書き込みデータのための別のクラスにNSMutableDictionary
任意のアイデアをNSMutable辞書を使用するには?
どのように.... iphoneでplistファイルからの読み取りおよび書き込みデータのための別のクラスにNSMutableDictionary
任意のアイデアをNSMutable辞書を使用するには?
あなたはNSDictionary referenceでで見つけることができるように、このクラスは、ファイルinitWithContentsOfFile:(NSString *)path
からNSDictionaryのを作成するための方法があります。
ここで、myDictionaryはplist名です(plistがリソースバンドルの場合)。 あなたはこの方法で、ディスク上のplistを書くことができます。
[dict writeToFile:filePath atomically: YES];
filePathには、あなたの先のパスです。
このtutorialのPlistファイルの例を参照してください。
// Look in Documents for an existing plist file
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
myPlistPath = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat: @"%@.plist", plistName] ];
[myPlistPath retain];
// If it's not there, copy it from the bundle
NSFileManager *fileManger = [NSFileManager defaultManager];
if (![fileManger fileExistsAtPath:myPlistPath]) {
NSString *pathToSettingsInBundle = [[NSBundle mainBundle]
pathForResource:plistName ofType:@"plist"];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *path = [documentsDirectoryPath
stringByAppendingPathComponent:@"myApp.plist"];
NSMutableDictionary *plist = [NSDictionary dictionaryWithContentsOfFile: path];
myKey = (int)[[plist valueForKey:@"myKey"] intValue];
myKey2 = (bool)[[plist valueForKey:@"myKey2"] boolValue];
[plist setValue:myKey forKey:@"myKey"];
[plist writeToFile:path atomically:YES];
お返事ありがとうございました。 – donkarai
Bermardiさん、お世話になりました。 – donkarai