我見過幾篇關於如何不能在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