I am trying to save a CNContact using NSUserDefaults. its not saving for some reason I end up getting a SIGABART error. My code is
var objects = [CNContact]()
let myDefaults = NSUserDefaults.standardUserDefaults()
let myContacts = "myContact"
func getSavedContact(){
myDefaults.objectForKey(myContacts)
}
@IBAction func SAVE(sender: AnyObject) {
myDefaults.setValue(objects, forKey: myContacts)
getSavedContact()
}
any suggestions on how to fix this?
From Apple Developer Documentation
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
Chances are it doesn’t like attempting to store an array of CNContacts. You could try using NSData, or create a function that creates an NSDictionary from a CNContact with the pertinent information.
Thanks for that info. Are there any tutorials or examples you would recommend in order to help me do this?