Why does my data is not send to the Kinvey backend? My app keeps crashing and I get the SIGABRT
error. I have tried changing the String
to NSString
but that didn't help. For some reason, my dashboard in Kinvey does show API Calls and Data storage but it's not storing anything (I am a beginner).
import UIKit
class ReservationViewController: UIViewController {
@IBOutlet weak var userName: UITextField!
@IBOutlet weak var userEmail: UITextField!
@IBOutlet weak var userSeat: UITextField!
@IBOutlet weak var userDateTime: UIDatePicker!
@IBAction func sendReservation(sender: AnyObject) {
// STORE DATA
let store = KCSAppdataStore.storeWithOptions([
KCSStoreKeyCollectionName : "userReservation",
KCSStoreKeyCollectionTemplateClass : Booking.self
])
let reservation = Booking()
reservation.name = userName.text
reservation.email = userEmail.text
reservation.seats = userSeat.text
reservation.date = NSDate(timeIntervalSince1970: 1352149171) //sample date
store.saveObject(
reservation,
withCompletionBlock: { (objectsOrNil: [AnyObject]!, errorOrNil: NSError!) -> Void in
if errorOrNil != nil {
//save failed
NSLog("Save failed, with error: %@", errorOrNil.localizedFailureReason!)
} else {
//save was successful
NSLog("Successfully saved event (id='%@').", (objectsOrNil[0] as! NSObject).kinveyObjectId())
}
},
withProgressBlock: nil
)
}
class Booking : NSObject { //all NSObjects in Kinvey implicitly implement KCSPersistable
var entityId: String? //Kinvey entity _id
var name: NSString?
var email: NSString?
var seats: NSString?
var date: NSDate?
}
override func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]! {
return [
"entityId" : KCSEntityKeyId, //the required _id field
"name" : "name",
"email" : "email",
"seats" : "seats",
"date" : "date",
]
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}