How add data to a map












1















I use google cloud firestore and I have a map in the documents. I then want to push an updated map to the database.



The document looks like this:
enter image description here



My model for the document looks like this:



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


So, how can I create an object that looks like this, (String:Bool), and put that in a map?



I hope I have provided enough information, otherwise feel free to ask.



Thanks in advance!










share|improve this question

























  • So, do you want to update sharedUsers field for example? If so, have a look: firebase.google.com/docs/firestore/query-data/listen

    – Ahmed Osama
    Dec 29 '18 at 18:58
















1















I use google cloud firestore and I have a map in the documents. I then want to push an updated map to the database.



The document looks like this:
enter image description here



My model for the document looks like this:



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


So, how can I create an object that looks like this, (String:Bool), and put that in a map?



I hope I have provided enough information, otherwise feel free to ask.



Thanks in advance!










share|improve this question

























  • So, do you want to update sharedUsers field for example? If so, have a look: firebase.google.com/docs/firestore/query-data/listen

    – Ahmed Osama
    Dec 29 '18 at 18:58














1












1








1








I use google cloud firestore and I have a map in the documents. I then want to push an updated map to the database.



The document looks like this:
enter image description here



My model for the document looks like this:



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


So, how can I create an object that looks like this, (String:Bool), and put that in a map?



I hope I have provided enough information, otherwise feel free to ask.



Thanks in advance!










share|improve this question
















I use google cloud firestore and I have a map in the documents. I then want to push an updated map to the database.



The document looks like this:
enter image description here



My model for the document looks like this:



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


So, how can I create an object that looks like this, (String:Bool), and put that in a map?



I hope I have provided enough information, otherwise feel free to ask.



Thanks in advance!







ios arrays swift google-cloud-firestore flatmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 20:13









Mozahler

2,09151625




2,09151625










asked Dec 29 '18 at 13:13









Alexander SinghAlexander Singh

176




176













  • So, do you want to update sharedUsers field for example? If so, have a look: firebase.google.com/docs/firestore/query-data/listen

    – Ahmed Osama
    Dec 29 '18 at 18:58



















  • So, do you want to update sharedUsers field for example? If so, have a look: firebase.google.com/docs/firestore/query-data/listen

    – Ahmed Osama
    Dec 29 '18 at 18:58

















So, do you want to update sharedUsers field for example? If so, have a look: firebase.google.com/docs/firestore/query-data/listen

– Ahmed Osama
Dec 29 '18 at 18:58





So, do you want to update sharedUsers field for example? If so, have a look: firebase.google.com/docs/firestore/query-data/listen

– Ahmed Osama
Dec 29 '18 at 18:58












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53969880%2fhow-add-data-to-a-map%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53969880%2fhow-add-data-to-a-map%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

compose and upload a new article using a custom form

How to correct the classpath of spring boot application so that it contains a single, compatible version of...