我尝试在NSUserDefaults中存储Array对象。
我有以下代码片段:
var accounts = MyAccounts() var array:Array<MyAccounts.MyCalendar> = accounts.populateFromCalendars() NSUserDefaults.standardUserDefaults(). setObject(array,forKey: "test_storeAccounts_array") // <- get error here NSUserDefaults.standardUserDefaults().synchronize()
但是我得到异常:
does not implement methodSignatureForSelector: -- trouble ahead
我的班级结构:
class MyAccounts { /* ... */ class MyCalendar { var title:String? var identifier:String? var email:String? var calType:String? var isActive:Bool? var isMainAcount:Bool? init(){} } }
有任何想法吗?
确保你的类继承自NSObject
class MyAccounts:NSObject { /* ... */ class MyCalendar { var title:String? var identifier:String? var email:String? var calType:String? var isActive:Bool? var isMainAcount:Bool? init(){} } }