存储数组中的 NSNumbers 消失
因此,我将 NSNumber 对象的 NSMutableArray 存储到文件“times.plist”中,然后加载它并在启动时保留它,NSLog 显示正确的值,但后来 [times count] 等于 0。为什么 NSNumber 消失了?
times = [[NSMutableArray alloc] initWithObjects:[[NSNumber alloc] initWithFloat:time],nil];
...
[times writeToFile:@"times.plist" atomically:YES];
...
times = [[NSMutableArray arrayWithContentsOfFile:@"times.plist"] retain];
NSLog(@"%f",[[times objectAtIndex:0] floatValue]);
So I stored an NSMutableArray of NSNumber objects into the file "times.plist" then I load it and retain it on launch and the NSLog shows the correct value, but later the [times count] equals 0. Why are the NSNumbers disappearing?
times = [[NSMutableArray alloc] initWithObjects:[[NSNumber alloc] initWithFloat:time],nil];
...
[times writeToFile:@"times.plist" atomically:YES];
...
times = [[NSMutableArray arrayWithContentsOfFile:@"times.plist"] retain];
NSLog(@"%f",[[times objectAtIndex:0] floatValue]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,笨笨笨笨。永远不要做我做过的事。在我的-init中;方法我已经用代码启动了我的时间数组:
并且我试图用以下方法恢复它们:
但是我在启动它之前恢复它并且每次都会删除它。从我的错误中吸取教训并检查你的 -init; 的顺序方法。总是。
Okay DUMB DUMB DUMB. Never do what I did. in my -init; method i had already initiated my times array with the code:
and I was trying to restore them with:
BUT I was restoring it BEFORE I was initiating it and that erased it every time. Learn from my mistake and check the order of your -init; methods. ALWAYS.