【发布时间】:2016-09-19 06:56:58
【问题描述】:
我在使用 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之前我没有任何错误。有什么想法吗? 提前谢谢你
【问题讨论】:
标签: ios swift firebase firebase-realtime-database swift3