我使用 google cloud firestore ,并且文档中有地图。然后,我想将更新的地图推送到数据库。
我的文档模型如下:
import Foundation
import Firestore
protocol DocumentSerializable {
init?(dictionary:[String:Any])
}
struct Exercise {
var title: String
var language: String
var translated: String
var uid: String
var userId: String
var dueDate: Int
var lastOpen: Int
var words: Array<Any>
var sharedUsers: [String: Bool]
var dictionary:[String:Any] {
return [
"title":title,
"language":language,
"translated":translated,
"uid":uid,
"userId":userId,
"dueDate":dueDate,
"lastOpen":lastOpen,
"words":words,
"sharedUsers":sharedUsers
]
}
}
extension Exercise : DocumentSerializable {
init?(dictionary: [String : Any]) {
guard let title = dictionary["title"] as? String,
let language = dictionary["language"] as? String,
let translated = dictionary["translated"] as? String,
let uid = dictionary["uid"] as? String,
let userId = dictionary["userId"] as? String,
let dueDate = dictionary["dueDate"] as? Int,
let lastOpen = dictionary["lastOpen"] as? Int,
let words = dictionary["words"] as? Array<Any>,
let sharedUsers = dictionary["sharedUsers"] as? [String: Bool]
else {return nil}
self.init(title: title, language: language, translated: translated, uid: uid, userId: userId, dueDate: dueDate, lastOpen: lastOpen, words: words, sharedUsers: sharedUsers)
}
}
那么,如何创建一个看起来像这样的对象(String:Bool)并将其放在地图中?
我希望我提供了足够的信息,否则请随时提出。
谢谢!