読みとの.plistへ/から番号を保存することはできません
-
21-09-2019 - |
質問
私は名前propertys.plistでプロパティリストを作成しました。それから私はこれを書いてます:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"speicherung.plist"];
NSMutableArray *plistData = [[NSMutableArray arrayWithContentsOfFile:finalPath] retain];
int a = [[plistData objectAtIndex:1] intValue];
NSLog(@"%i", a); // returns always 0 - Even If I set a other number in the plist
a = a + 1;
NSNumber *ff = [NSNumber numberWithInt:a];
[plistData insertObject:ff atIndex:1];
NSLog(@"%@", [plistData objectAtIndex:1]); // returns 1 - right, because 0 + 1 = 1
[plistData writeToFile:finalPath atomically:YES];
私は再びこのコードを実行すると、私はいつも二の最初のNSLogで数0と番号1を取得します。なぜ?
このコードはiPhone用です。
解決
[plistData objectAtIndex:1];
このはするNSNumberです。だから、これにObjCオブジェクトのアドレスが整数に変換し、奇妙な値を与える、a
に割り当てられています。使用それから整数を抽出する-intValue
ます。
int a = [[plistData objectAtIndex:1] intValue];
所属していません StackOverflow