Am new to Swift but as am learning I am also trying to develop my own app.
So I have a Struct that is Codable as it’s connecting to FireStore but I can’t get me head around how I add records. I have written a function called addRecord -
func addRecord(_ event: Events) {
do {
let _ = try db.collection(K.FStore.eventsCollection).addDocument(from: event)
}
catch {
print("There was an error while trying to save a event \(error.localizedDescription).")
}
}
This is my Events Struct -
struct Events: Codable, Identifiable {
@DocumentID var id: String? = UUID().uuidString
var name: String
var venue: String
var description: String
var date: String
var time: String
var passcode: String
var privateEvent: Bool
@ServerTimestamp var createdTime: Timestamp?
}
I have a form to capture all the details but I am having trouble passing a Event to my function addRecord. So I thought create a variable called newEvent = Events, then populate it with all my fields and then call the addRecord function with newEvent. But I can’t even create the variable I get a decodable error. If I take the Codable bit of the struct I can create it.
I tried following a long with a tutorial from Peter Friese but it was far too advanced, he uses classes and code I can’t even read.
Not sure if there is enough information to be of any help. Obviously I have more code than what’s shown.
Thanks,
Dave