0

this is a very hard question to ask because I don't want to flood you with all of my code, being that most of it is not pertinent to the problem. So I won't be to surprised if this goes unanswered. Although, it could be something hella simple that I am missing haha. Here it goes:

So my app is storing an array via [encoder] in my appDelegate. The app is full of objects that are creates in a separate NSObject class. Think of it this way for examples sake: I have my main viewController class. And in appDelegate I define/encode an array of objects. Now in my main, I fill the array with 10 "cars". My car class has variables such as color, make, model, etc.. Now when I save and relaunch the app, the array that I have saved is now an array containing 10 elements, but it seems to have forgotten all of the variables for each instance of the car class.

When I relaunch the app, If I call NSLog(@"%@",array in appDelegate); It prints 10 lines that look a lot like this: "" So I know the array is being stored with 10 elements, and 10 elements are saved, but like i said, all of the variables are gone.

Note: On the first run of the app, and the array is being filled for the first time, I can access all the variables perfectly, and nothing is wrong.

Thank you for any help that I can get!!

4

2 回答 2

0

您的主类以及您放入数组的所有对象都需要符合 NSCoding。如果数组中的对象不符合 NSCoding,它们将不会自动编码。

于 2013-04-27T06:37:18.827 回答
0

我们需要在“car”类上查看您实现 initWithCoder 和 encodeWithCoder 的代码。如果你还没有实现它们,那是你的问题。

当前可能发生的是,只有这些方法的超类实现被调用。这意味着将重新创建正确的类,但不会保存或恢复任何数据。

NSCoding 协议参考文档

于 2013-04-27T07:27:09.703 回答