使用Firebase Swift 2版本,我能够做到:
something = ["someOptionalData": optionalData]
ref.updateChildValues(something,......})
转换为Swift 3&最新的Firebase,我收到了这个错误:
Cannot store object of type _SwiftValue at optionalData. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.
经过一些谷歌搜索,人们都说firebase不接受可选类型。
所以我可以知道除此之外处理它的更好方法是什么:
if let unwrappedOptionalData = optionalData {
something = [
"someOptionalData": unwrappedOptionalData
]
} else {
something = [
"someOptionalData": true
]
}
ref.updateChildValues(something,......)
答案 0 :(得分:0)
尝试: -
something = ["someOptionalData": optionalData!]
ref.updateChildValues(something,......)
鉴于 optionalData 的类型为: - NSNumber , NSString , NSDictionary 或 NSArray