Kinvey DataStore不会保存

时间:2017-02-09 01:24:20

标签: ios xcode kinvey

我想通过编写一个简单的应用程序来保存Kinvey文档,以便在“Book”集合中保存对象“book”

不幸的是我收到以下错误

dyld_sim`dyld_fatal_error:

我的代码如下

的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.
}


}

当我从ViewController.swift中注释掉以下内容时,我的代码无问题地运行

dataStore.save(book) { book, error in
            if let book = book {
                //succeed
                print("Book: \(book)")
            } else {
                //fail
            }// close else
        }  //closesave block

在备份上生成了一个新用户,但没有任何内容添加到图书集

以下是我的调试器窗口enter image description here

的屏幕截图

1 个答案:

答案 0 :(得分:0)

布赖恩,

看看它是否可以用Clean&amp; amp;构建(或者重新启动Xcode)。您也可以考虑从〜/ Library / Developer / Xcode / DerivedData中删除相关文件夹。

向我提供您所获得的错误的屏幕截图。如果你能为我提供样本项目,你会发现错误很大。

此外,您使用的是哪个版本的SDK?

谢谢, Pranav Kinvey支持