I have initialization of the array
var defaults = NSUserDefaults.standardUserDefaults()
var initObject: [CPaymentInfo]? = defaults.objectForKey(\"pa
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.