gpt4 book ai didi

ios - 设置值 Firebase - Swift 3

转载 作者:搜寻专家 更新时间:2023-11-01 07:20:09 25 4
gpt4 key购买 nike

我在使用 Swift 3 和 Firebase 时遇到了一些问题。我的错误是 Thread 1 Signal SIGABRT.我的错误是这样的:

Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(setValue:) Cannot store object of type _SwiftValue at book_key. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'

我的代码是这样的:

var book_key, book_title, book_authors, book_publisher, number_pages, book_price, book_urlPicture1, book_urlPicture2, book_condition: String!

var ref = FIRDatabase.database().reference().child("Books").child("User's books")
book_key = ref.childByAutoId().key


let valuesBook: NSDictionary = ["book_key": book_key, "book_title": book_title, "book_author": book_authors, "book_price": book_price, "book_publisher": book_publisher, "page_count": number_pages, "book_description": "", "book_urlImage": book_urlPicture1, "book_urlImage2": book_urlPicture2, "book_condition": book_condition]

ref.child(book_key).setValue(valuesBook)

如果我在我的应用程序中打印我的 valuesBook,结果是绝对正确的。像这样:

{
"book_author" = Gg;
"book_condition" = "Very Good";
"book_description" = "";
"book_key" = "-KS0DIr6cQkI0oxsgwPU";
"book_price" = 3;
"book_publisher" = Jj;
"book_title" = Gg;
"book_urlImage" = "https://firebasestorage.googleapis.com/v0/b/myapp.appspot.com/o/book_key%2F-KS0DIr6cQkI0oxsgwPUfirstImage.jpg?alt=media&token=231324bd-5b3a-4e3e-935f-2f1177da404a";
"book_urlImage2" = "https://firebasestorage.googleapis.com/v0/b/loginsample-myapp.appspot.com/o/book_key%2F-KS0DIr6cQkI0oxsgwPUsecondImage.jpg?alt=media&token=cc207ba4-46a6-4552-a65c-13ef7c4df5ee";
"page_count" = 5;

}

结果保存在我的数据库中,但应用程序崩溃了。在 swift 3 之前我没有任何错误。有什么想法吗?提前谢谢你

最佳答案

当你的字典中有 Optionals 时,这似乎发生在 swift 3 中,尝试将你的变量声明为 String,初始值为空字符串而不是 String! , 像这样

var book_key = "", book_title = "", book_authors = "", book_publisher = "", number_pages = "", book_price = "", book_urlPicture1 = "", book_urlPicture2 = "", book_condition = ""

关于ios - 设置值 Firebase - Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39567065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com