为什么我的数据不会发送到Kinvey后端?我的应用程序一直崩溃,我收到SIGABRT
错误。我尝试将String
更改为NSString
,但这没有用。出于某种原因,我在Kinvey的仪表板确实显示了API调用和数据存储,但它没有存储任何东西(我是初学者)。
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.
}
}
答案 0 :(得分:1)
如果这实际上是您的代码,而不仅仅是您在复制粘贴时犯的错误,那么问题是您的Booking
类目前是ReservationViewController
中的嵌套类,并且您实现了{{ 1}}作为hostToKinveyPropertyMapping
的方法。
相反,为您的Kinvey类创建一个新文件:
ReservationViewController
从视图控制器中删除该代码。此外,请确保您安全地展开所有可选值,并确认您的集合确实名为“userReservation”。