我见过几篇关于如何不能在NSUserDefaults
中保存基于NSMutableArray
的对象的文章,但有一种方法可以使用[NSKeyedArchiver]
并使用NSCoder
对其进行编码,尽管我正在努力去理解如何去做并希望有人能够帮助。如何在NSUserDefaults中保存“自定义类对象”的NSMutableArray?
Student *student1 = [Student studentWithImage:[UIImage imageNamed:@"default"] withForename:@"John" withSurname:@"Smith" withAddress:@"3 Fake Road, Faketown, FA31 KEE" withDateOfBirth:[dateFormatter dateFromString:@"17-Jul-93"] withAge:24];
[studentArray addObject:student1];
我想这和其他一些类似Students
保存到我的NSMutableArray
studentArray
。然后我想将这个数组保存到NSUserDefaults
并重新加载它。
I have seen this post here看起来像是我的问题的正确答案,但我需要帮助实现它到我的代码,因为我很难理解它! 感谢
你想保存studentArr唉在userdafaults? – KKRocks
@KKRocks多数民众赞成在正确的,我需要保存的数组包含它的属性,如学生图像,名称,出生日期等。 – Manesh
@Mahesh检查我的答案,并添加你的财产,因为我提到。 – KKRocks