How to get an array field from Firestore and write in struct field in Swift?How to call Objective-C code from SwiftSwift for loop: for index, element in array?Swift Beta performance: sorting arraysSplit a String into an array in Swift?How do I write dispatch_after GCD in Swift 3, 4, and 5?C - struct returned from function not assigned to variableFIreStore on New Swift Project - FIRAuth getUID implementationCloud Firestore and data modeling: From RDBMS to No-SQLAssign additional field when unmarshalling JSON object to GO structAndroid Firestore - Update object in Array leads to unsupported type
Everyone but three
I want to identify a part from a photo
Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation
How slow can a car engine run?
Demographic consequences of closed loop reincarnation
What did Jeremy Hunt mean by "slipped" to miss a vote?
Is encryption still applied if you ignore the SSL certificate warning for self signed?
Is surviving this (blood loss) scenario possible?
Why teach C using scanf without talking about command line arguments?
Why won't some unicode characters print to my terminal?
Should I use a resistor between the gate driver and MOSFET (gate pin)?
When is the Circle of Dreams druid's Walker in Dreams feature used?
Difference between c++14 and c++17 using: `*p++ = *p`
Why do space operations use "nominal" to mean "working correctly"?
Zhora asks Deckard: "Are you for real?". Was this meant to be significant?
The most secure way to handle someone forgetting to verify their account?
How can electric field be defined as force per charge, if the charge makes its own, singular electric field?
Term “console” in game consoles
What details should I consider before agreeing for part of my salary to be 'retained' by employer?
Who determines when road center lines are solid or dashed?
Why jet engines sound louder on the ground than inside the aircraft?
Is this Android phone Android 9.0 or Android 6.0?
"This used to be my phone number"
What happens if a company buys back all of its shares?
How to get an array field from Firestore and write in struct field in Swift?
How to call Objective-C code from SwiftSwift for loop: for index, element in array?Swift Beta performance: sorting arraysSplit a String into an array in Swift?How do I write dispatch_after GCD in Swift 3, 4, and 5?C - struct returned from function not assigned to variableFIreStore on New Swift Project - FIRAuth getUID implementationCloud Firestore and data modeling: From RDBMS to No-SQLAssign additional field when unmarshalling JSON object to GO structAndroid Firestore - Update object in Array leads to unsupported type
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
The problem that I faced is, I can reach every field in Firestore and write in structs except array&map field.
My firestore data is something like:
let data : [String : Any] = [
"name" : "House A",
"price" : 2000,
"contents" : [
"water" : true,
"internet" : false
]
]
Here is getDocument function:
let docRef = db.collection("example").document("example")
docRef.getDocument (document, error) in
if let document = document, document.exists
let data = Houses(Doc: document)
...
...
...
else
print(error, "Item not found")
Here is my structs :
struct Houses
var name: String?
var price: Int
var contents : Contents
init(Doc: DocumentSnapshot)
self.name = Doc.get("name") as? String ?? ""
self.price = Doc.get("price") as! Int
self.contents = Doc.get("contents") as! Contents
struct Contents
var water: Bool
var internet : Bool
init?(data: [String: Any])
guard let water = data["water"] as? Bool,
let internet = data["internet"] as? Bool else
return nil
self.water = water
self.internet = internet
The other version of Contents :
struct Contents
var water: Bool
var internet : Bool
init(Doc: DocumentSnapshot)
self.water = Doc.get("water") as! Bool
self.internet = Doc.get("internet") as! Bool
UPDATED
The problem solved with changing this line:
self.contents = Doc.get("contents") as! Contents
to;
self.contents = Contents(data: Doc.get("contents") as! [String : Any])
name and price returns what I expected but contents always return nil. I tried to configure Contents but results are same. I think, I have to configure struct named Contents.
Any help would be appreciated.
swift firebase struct google-cloud-firestore
add a comment |
The problem that I faced is, I can reach every field in Firestore and write in structs except array&map field.
My firestore data is something like:
let data : [String : Any] = [
"name" : "House A",
"price" : 2000,
"contents" : [
"water" : true,
"internet" : false
]
]
Here is getDocument function:
let docRef = db.collection("example").document("example")
docRef.getDocument (document, error) in
if let document = document, document.exists
let data = Houses(Doc: document)
...
...
...
else
print(error, "Item not found")
Here is my structs :
struct Houses
var name: String?
var price: Int
var contents : Contents
init(Doc: DocumentSnapshot)
self.name = Doc.get("name") as? String ?? ""
self.price = Doc.get("price") as! Int
self.contents = Doc.get("contents") as! Contents
struct Contents
var water: Bool
var internet : Bool
init?(data: [String: Any])
guard let water = data["water"] as? Bool,
let internet = data["internet"] as? Bool else
return nil
self.water = water
self.internet = internet
The other version of Contents :
struct Contents
var water: Bool
var internet : Bool
init(Doc: DocumentSnapshot)
self.water = Doc.get("water") as! Bool
self.internet = Doc.get("internet") as! Bool
UPDATED
The problem solved with changing this line:
self.contents = Doc.get("contents") as! Contents
to;
self.contents = Contents(data: Doc.get("contents") as! [String : Any])
name and price returns what I expected but contents always return nil. I tried to configure Contents but results are same. I think, I have to configure struct named Contents.
Any help would be appreciated.
swift firebase struct google-cloud-firestore
self.contents = Contents(Doc.get("contents"))
– Sachin Vas
Mar 26 at 12:47
@SachinVas Yeah that was the problem. Thank you so much!!
– Berkan C.
Mar 26 at 13:24
add a comment |
The problem that I faced is, I can reach every field in Firestore and write in structs except array&map field.
My firestore data is something like:
let data : [String : Any] = [
"name" : "House A",
"price" : 2000,
"contents" : [
"water" : true,
"internet" : false
]
]
Here is getDocument function:
let docRef = db.collection("example").document("example")
docRef.getDocument (document, error) in
if let document = document, document.exists
let data = Houses(Doc: document)
...
...
...
else
print(error, "Item not found")
Here is my structs :
struct Houses
var name: String?
var price: Int
var contents : Contents
init(Doc: DocumentSnapshot)
self.name = Doc.get("name") as? String ?? ""
self.price = Doc.get("price") as! Int
self.contents = Doc.get("contents") as! Contents
struct Contents
var water: Bool
var internet : Bool
init?(data: [String: Any])
guard let water = data["water"] as? Bool,
let internet = data["internet"] as? Bool else
return nil
self.water = water
self.internet = internet
The other version of Contents :
struct Contents
var water: Bool
var internet : Bool
init(Doc: DocumentSnapshot)
self.water = Doc.get("water") as! Bool
self.internet = Doc.get("internet") as! Bool
UPDATED
The problem solved with changing this line:
self.contents = Doc.get("contents") as! Contents
to;
self.contents = Contents(data: Doc.get("contents") as! [String : Any])
name and price returns what I expected but contents always return nil. I tried to configure Contents but results are same. I think, I have to configure struct named Contents.
Any help would be appreciated.
swift firebase struct google-cloud-firestore
The problem that I faced is, I can reach every field in Firestore and write in structs except array&map field.
My firestore data is something like:
let data : [String : Any] = [
"name" : "House A",
"price" : 2000,
"contents" : [
"water" : true,
"internet" : false
]
]
Here is getDocument function:
let docRef = db.collection("example").document("example")
docRef.getDocument (document, error) in
if let document = document, document.exists
let data = Houses(Doc: document)
...
...
...
else
print(error, "Item not found")
Here is my structs :
struct Houses
var name: String?
var price: Int
var contents : Contents
init(Doc: DocumentSnapshot)
self.name = Doc.get("name") as? String ?? ""
self.price = Doc.get("price") as! Int
self.contents = Doc.get("contents") as! Contents
struct Contents
var water: Bool
var internet : Bool
init?(data: [String: Any])
guard let water = data["water"] as? Bool,
let internet = data["internet"] as? Bool else
return nil
self.water = water
self.internet = internet
The other version of Contents :
struct Contents
var water: Bool
var internet : Bool
init(Doc: DocumentSnapshot)
self.water = Doc.get("water") as! Bool
self.internet = Doc.get("internet") as! Bool
UPDATED
The problem solved with changing this line:
self.contents = Doc.get("contents") as! Contents
to;
self.contents = Contents(data: Doc.get("contents") as! [String : Any])
name and price returns what I expected but contents always return nil. I tried to configure Contents but results are same. I think, I have to configure struct named Contents.
Any help would be appreciated.
swift firebase struct google-cloud-firestore
swift firebase struct google-cloud-firestore
edited Mar 26 at 13:29
Berkan C.
asked Mar 26 at 10:03
Berkan C.Berkan C.
53 bronze badges
53 bronze badges
self.contents = Contents(Doc.get("contents"))
– Sachin Vas
Mar 26 at 12:47
@SachinVas Yeah that was the problem. Thank you so much!!
– Berkan C.
Mar 26 at 13:24
add a comment |
self.contents = Contents(Doc.get("contents"))
– Sachin Vas
Mar 26 at 12:47
@SachinVas Yeah that was the problem. Thank you so much!!
– Berkan C.
Mar 26 at 13:24
self.contents = Contents(Doc.get("contents"))
– Sachin Vas
Mar 26 at 12:47
self.contents = Contents(Doc.get("contents"))
– Sachin Vas
Mar 26 at 12:47
@SachinVas Yeah that was the problem. Thank you so much!!
– Berkan C.
Mar 26 at 13:24
@SachinVas Yeah that was the problem. Thank you so much!!
– Berkan C.
Mar 26 at 13:24
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354358%2fhow-to-get-an-array-field-from-firestore-and-write-in-struct-field-in-swift%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
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354358%2fhow-to-get-an-array-field-from-firestore-and-write-in-struct-field-in-swift%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
self.contents = Contents(Doc.get("contents"))
– Sachin Vas
Mar 26 at 12:47
@SachinVas Yeah that was the problem. Thank you so much!!
– Berkan C.
Mar 26 at 13:24