Attempt to insert non-property list object when trying to save a custom object in Swift 3

后端 未结 5 1837
北海茫月
北海茫月 2020-11-27 14:58

I have a simple object which conforms to the NSCoding protocol.

import Foundation

class JobCategory: NSObject, NSCoding {
    var id: Int
    v         


        
5条回答
  •  温柔的废话
    2020-11-27 15:18

    Save dictionary Into userdefault

    let data = NSKeyedArchiver.archivedData(withRootObject: DictionaryData)
    UserDefaults.standard.set(data, forKey: kUserData)
    

    Retrieving the dictionary

    let outData = UserDefaults.standard.data(forKey: kUserData)
    let dict = NSKeyedUnarchiver.unarchiveObject(with: outData!) as! NSDictionary
    

提交回复
热议问题