1

I'm currently working on a Swift application that interacts with the Shopify API through their Mobile Buy SDK. I'm having issues saving the cart to the device. Everything else works fine, but when I use the following code to save the cart to the device:

  func saveCart() {
    NSUserDefaults.standardUserDefaults().setObject(cart, forKey: "cart")
    println("cart saved")
  }

I receive the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object <BUYCart: 0x7fb5e30512f0> for key cart'
Alex Smith
  • 385
  • 4
  • 21

1 Answers1

0

From the NSUserDefaults class reference:

The NSUserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Booleans, and URLs. A default object must be a property list, that is, an instance of (or for collections a combination of instances of): NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of object, you should typically archive it to create an instance of NSData. For more details, see Preferences and Settings Programming Guide.

Hope this helps!

Benjy Wiener
  • 1,085
  • 2
  • 9
  • 27