I am tying to understand the Kinvey docs by writing a simple app to save an object "book" in a collection "Book"
Unfortunately I receive the following error
dyld_sim`dyld_fatal_error:
My code is as follows
AppDelegate
import UIKit
import Kinvey
import SVProgressHUD
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
lazy var fileStore: FileStore = {
return FileStore.getInstance()
}()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Kinvey.sharedClient.initialize(
appKey: "kid_rJngK8I_x",
appSecret: "6439a2ee96ef412083f10108666f6004"
)
if let _ = Kinvey.sharedClient.activeUser {
//do nothing
} else {
SVProgressHUD.show()
User.exists(username: "test") { exists, error in
if exists {
User.login(username: "test", password: "test") { user, error in
SVProgressHUD.dismiss()
if let _ = user {
//do nothing
} else {
//do something!
}
}
} else {
User.signup(username: "test", password: "test") { user, error in
SVProgressHUD.dismiss()
if let _ = user {
//do nothing
} else {
//do something!
}
}
}
}
}
return true
}
Book.swift
import Foundation
import Kinvey
class Book: Entity {
dynamic var title: String?
dynamic var authorName: String?
override class func collectionName() -> String {
//return the name of the backend collection corresponding to this entity
return "Book"
}
//Map properties in your backend collection to the members of this entity
override func propertyMapping(_ map: Map) {
//This maps the "_id", "_kmd" and "_acl" properties
super.propertyMapping(map)
//Each property in your entity should be mapped using the following scheme:
//<member variable> <- ("<backend property>", map["<backend property>"])
title <- ("title", map["title"])
authorName <- ("authorName", map["author"])
}
}
ViewController
import UIKit
import Kinvey
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let dataStore = DataStore<Book>.collection()
let book = Book()
book.title = "Steal This Book"
book.authorName = "Abbey Hoffman"
print("Abbey Hoffman")
dataStore.save(book) { book, error in
if let book = book {
//succeed
print("Book: \(book)")
} else {
//fail
}// close else
} //closesave block
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
When I comment out the following from ViewController.swift my code runs without issue
dataStore.save(book) { book, error in
if let book = book {
//succeed
print("Book: \(book)")
} else {
//fail
}// close else
} //closesave block
A new user is generated on the backed but nothing is added to the book collection
Bryan,
See if it can be solved with a Clean & Build (or perhaps relaunch Xcode). You might also consider deleting the relevant folders from ~/Library/Developer/Xcode/DerivedData.
Provide me with the screenshot of the error that you are getting. If you could provide me with sample project where you are seeing the error that would be great.
Also, what version of the SDK you are using?
Thanks, Pranav Kinvey Support
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.