So basically I have been having an issue with an error that keeps popping up in my code when I try to get documents from Firestore. Im not really sure why, can someone please clarify it to me. I am trying to use the structure of Log and to capture the different fields in a document. After this, I want add it to an array of Logs so that I can then present in my view.
My code:
import Foundation
import Firebase
This is the Log structure which I wanted to use to model my data:
struct Log {
// MARK: - Properties
var date : Date
var leftUO : Bool
var leftUI : Bool
var leftLI : Bool
var leftLO : Bool
var rightUO : Bool
var rightUI : Bool
var rightLI : Bool
var rightLO : Bool
}
And this is the way I wanted to retrieve the data from firebase and store it locally.
struct LogsModel {
let storage = Firestore.firestore()
func retrieveLogs(uid: String, user : String) -> [Log] {
var logs : [Log] = []
storage.collection("/LOGS" + user + uid).getDocuments { (snapshot, error) in
guard let documents = snapshot?.documents else {
print(error?.localizedDescription ?? "Documents not retrived")
return
}
for document in documents {
let date = document.get(Constants.FirebaseConstants.DATE)
let fieldLLI = document.get(Constants.FirebaseConstants.LEFTLOWERINNER)
let fieldLLO = document.get(Constants.FirebaseConstants.LEFTLOWEROUTER)
let fieldLUO = document.get(Constants.FirebaseConstants.LEFTLOWEROUTER)
let fieldLUI = document.get(Constants.FirebaseConstants.LEFTUPPERINNER)
let fieldRLI = document.get(Constants.FirebaseConstants.RIGHTLOWERINNER)
let fieldRLO = document.get(Constants.FirebaseConstants.RIGHTLOWEROUTER)
let fieldRUO = document.get(Constants.FirebaseConstants.RIGHTUPPEROUTER)
let fieldRUI = document.get(Constants.FirebaseConstants.RIGHTUPPERINNER)
let log = Log(date: date as! Date,
leftUO: fieldLUO as! Bool,
leftUI: fieldLUI as! Bool,
leftLI: fieldLLI as! Bool,
leftLO: fieldLLO as! Bool,
rightUO: fieldRUO as! Bool,
rightUI: fieldRUI as! Bool,
rightLI: fieldRLI as! Bool,
rightLO: fieldRLO as! Bool)
// TODO - extract document into Log struct and add that to logs array
logs += [log]
}
}
return logs
}
}
I hope I clarified my issue enough. Thanks in advance for your help I really appreciate it
Posting this as a community wiki since it's based on @Aheze's comments:
The error that you are getting Editor placeholder in source file
, means that there is a placeholder somewhere in your code, which will be indicated by a grey or blue block and will need to be replaced by something of that value.
Here is an example of a placeholder in the code
Also, make sure to do a project clean before running it again as this can also be getting triggered by Xcode for no reason at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.