gpt4 book ai didi

database - 向 Kinvey 发送数据时出现 SIGABRT 错误

转载 作者:行者123 更新时间:2023-11-30 10:04:52 24 4
gpt4 key购买 nike

为什么我的数据没有发送到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.
}
}

最佳答案

如果这实际上是您的代码,而不仅仅是您在复制粘贴时犯的错误,则问题在于您的 Booking 类当前是 ReservationViewController 中的嵌套类,并且您将 hostToKinveyPropertyMapping 实现为 ReservationViewController 的方法。

相反,为您的 Kinvey 类创建一个新文件:

class Booking: NSObject {
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" //You also had an extra comma after the last item of this dictionary.
]
}
}

并从 View Controller 中删除该代码。另外,请确保安全地解开所有可选值,并确认您的集合确实名为“userReservation”。

关于database - 向 Kinvey 发送数据时出现 SIGABRT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36576835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com