【问题标题】:Kinvey DataStore Does Not SaveKinvey DataStore 不保存
【发布时间】:2017-02-09 01:24:19
【问题描述】:

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

很遗憾,我收到以下错误

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"])
}
}

视图控制器

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

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

下面是我的调试器窗口截图

【问题讨论】:

    标签: ios xcode kinvey


    【解决方案1】:

    布莱恩,

    看看它是否可以通过 Clean & Build(或者重新启动 Xcode)来解决。您也可以考虑从 ~/Library/Developer/Xcode/DerivedData 中删除相关文件夹。

    向我提供您遇到的错误的屏幕截图。如果您可以向我提供您看到错误的示例项目,那就太好了。

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

    谢谢, 普拉纳夫 金维支持

    【讨论】:

    • 清理和构建并重新启动 XCode 不幸的是没有工作。我编辑了我的原始帖子以包含我的调试器窗口的屏幕截图。
    • 我正在使用与 iOS 10、swift 3、xcode 8 兼容的最新 SDK
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 2016-06-05
    相关资源
    最近更新 更多