Can't insert object in the array, that I want add to User Defaults

后端 未结 1 502
[愿得一人]
[愿得一人] 2021-01-14 05:42

I have initialization of the array

    var defaults = NSUserDefaults.standardUserDefaults()
    var initObject: [CPaymentInfo]? = defaults.objectForKey(\"pa         


        
相关标签:
1条回答
  • 2021-01-14 06:24

    The answer is in the error message:

    Attempt to insert non-property list object ( "cash_app.CPaymentInfo" ) for key paymentData'
    

    You cannot put arbitrary classes into a property list (such as NSUserDefaults). There is a specific list of classes that are acceptable. If you have other classes you want to store, you need to convert them to an acceptable class.

    For documentation on saving non-property-list classes to user defaults, see Storing NSColor in UserDefaults. While that article focuses on NSColor, it applies to any object that conforms to NSCoding. See also the Note at Introduction to Property Lists.

    0 讨论(0)
提交回复
热议问题