As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
I have been trying to connect my app to my backend on Kinvey, but i am not getting it to work. The backend is connected (i can see the API calls). I have an app where i want to save the data of someones: name, email, number of seats and the date and time. Below you can see my code. Does anyone know why it is not saving to Kinvey?
import UIKit
class ReservationViewController: UIViewController {
@IBOutletweakvar userName: UITextField!
@IBOutletweakvar userEmail: UITextField!
@IBOutletweakvar userSeat: UITextField!
@IBOutletweakvar userDateTime: UIDatePicker!
class Booking : NSObject { //all NSObjects in Kinvey implicitly implement KCSPersistable
Your code looks good to me. What error do you see when you call the saveObject()?
Thanks, Pranav Kinvey Support
E
Edward LoPinto
said
over 7 years ago
Pranav, isn't the problem that Booking is a nested class inside of ReservationViewController? hostToKinveyPropertyMapping is currently implemented as a method of ReservationViewController, and not a method of Booking, so when KinveyKit tries checks your Booking object, it doesn't have the method.
I think it would be better if you create a new file - just to keep things clear - and move your Booking class to the new file, then implement hostToKinveyPropertyMapping as part of the Booking class. In fact, another person named Kevin posted the exact same question on stackoverflow.com, which I answered, and never received an upvote for! :) Here was my answer: http://stackoverflow.com/a/36757534/3003312
Hope that helps.
P
Pranav J
said
over 7 years ago
Answer
Edward,
Yes, you are right and thanks for catching it - hostToKinveyPropertyMapping() should be a function of class Booking. I missed on the closing brace.
Kevin O
Dear users,
I have been trying to connect my app to my backend on Kinvey, but i am not getting it to work. The backend is connected (i can see the API calls). I have an app where i want to save the data of someones: name, email, number of seats and the date and time. Below you can see my code. Does anyone know why it is not saving to Kinvey?
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!
class Booking : NSObject { //all NSObjects in Kinvey implicitly implement KCSPersistable
var entityId: String? //Kinvey entity _id
var name: String?
var email: String?
var seats: String?
var date: NSDate?
}
override func hostToKinveyPropertyMapping() -> [NSObject : AnyObject]! {
return [
"entityId" : KCSEntityKeyId, //the required _id field
"name" : "name",
"email" : "email",
"seats" : "seats",
"date" : "date",
]
}
@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
)
}
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.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Edward,
Yes, you are right and thanks for catching it - hostToKinveyPropertyMapping() should be a function of class Booking. I missed on the closing brace.
Thanks,
Pranav
Kinvey Support
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstPranav J
Your code looks good to me. What error do you see when you call the saveObject()?
Thanks,
Pranav
Kinvey Support
Edward LoPinto
Pranav, isn't the problem that Booking is a nested class inside of ReservationViewController? hostToKinveyPropertyMapping is currently implemented as a method of ReservationViewController, and not a method of Booking, so when KinveyKit tries checks your Booking object, it doesn't have the method.
I think it would be better if you create a new file - just to keep things clear - and move your Booking class to the new file, then implement hostToKinveyPropertyMapping as part of the Booking class. In fact, another person named Kevin posted the exact same question on stackoverflow.com, which I answered, and never received an upvote for! :) Here was my answer: http://stackoverflow.com/a/36757534/3003312
Hope that helps.
Pranav J
Edward,
Yes, you are right and thanks for catching it - hostToKinveyPropertyMapping() should be a function of class Booking. I missed on the closing brace.
Thanks,
Pranav
Kinvey Support
-
Why do I get "Undefined symbols" errors when building with KinveyKit?
-
How do I register push tokens?
-
When using social login, to perform a log-out, do I need to log out of the social network, Kinvey, o
-
How can I assign additional properties to users?
-
Does KinveyKit support 64-bit ARM devices, such as iPhone 5s?
-
Authorization Token Invalid or Expired
-
BOOL and how it is stored in the database.
-
Offline saving throwing errors
-
Custom endpoint not able to form request object
-
Security through business logic
See all 437 topics