首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kinvey DataStore不保存

Kinvey DataStore不保存
EN

Stack Overflow用户
提问于 2017-02-09 09:24:20
回答 1查看 128关注 0票数 0

为了理解Kinvey文档,我编写了一个简单的应用程序,将对象"book“保存在集合"Book”中。

不幸的是,我收到以下错误

代码语言:javascript
复制
dyld_sim`dyld_fatal_error:

我的代码如下

AppDelegate

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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中注释掉以下代码时,我的代码运行起来没有任何问题

代码语言:javascript
复制
dataStore.save(book) { book, error in
            if let book = book {
                //succeed
                print("Book: \(book)")
            } else {
                //fail
            }// close else
        }  //closesave block

在备份上生成新用户,但不会向图书集合中添加任何内容

下面是我的调试器窗口的屏幕快照

EN

回答 1

Stack Overflow用户

发布于 2017-02-09 21:44:13

布莱恩

看看是否可以使用Clean & Build (或者重新启动Xcode)来解决这个问题。您还可以考虑从~/Library/Developer/Xcode/DerivedData中删除相关文件夹。

为我提供你得到的错误的屏幕截图。如果你能为我提供样本项目,在那里你看到的错误,将是很大的。

另外,您使用的是什么版本的SDK?

谢谢,Pranav Kinvey支持

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42126656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档