Very nice tutorial. Thank you! I have one question. When returning from the QuestionsView, you manually increased peopleAttended += 1 (27:05) locally instead of re-fetching the updated data. How could I do that? run the asynchronous function fetchData in the onFinish of the QuestionView component and update the view? Thank you in advance!
i got "The data couldn’t be read because it isn’t in the correct format." when running the code (6:05). Instead of showing the title, i get loading image.
Question: I want to save the quiz results so user can go back and see them afterwards. When I save / load to userdefaults because of the struct tappedAnswer: String = "" it always loses the users answer. How can I save and load the data keeping the users tappedAnswer?
I figured it out, with init(from decoder: Decoder) throws and self.tappedAnswer = try container.decodeIfPresent(String.self, forKey: .tappedAnswer) ?? ""
Thanks for the awesome lesson. In my environment the .data(as: Decodable) option in the Firestore.firestore() object does not exist. I tried using the latest Firebase Version as well as Version 9.6.0 as used in your video. In either version, there is only .data() and .data(with: ServerTimeStampBehaviour). Is .data(as: Decodable) a custom extension? For everyone who has the same issue as me and wants a fix: 1. Get the data with .data() let infoData = Firestore.firestore().collection("Quiz").document("Info").getDocument().data() 2. Manually parse the content of infoData onto the Info Model: let info = Info(title: infoData?["title"] as? String ?? "", peopleAttended: infoData?["peopleAttended"] as? Int ?? 0, rules: infoData?["rules"] as? [String] ?? []) Do the exact same thing with the questions Object in the .compactMap{} closure
Hi @@Kavsoft - just checked again - my XCode does not show the data(as:) option :/ I imported FirebaseFirestoreSwift. Maybe it is an issue with my environment. The work around works though for anyone who needs it :) #Learning :P
Hi , I tried the code and setup . I am getting this error 2023-05-11 09:59:01.464726-0500 Quiz_App[94732:4426386] 9.6.0 - [GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol. The data couldn’t be read because it isn’t in the correct format. Could you help me with this. 8:56
@@honamchow6676 I guess this is a bit late by anyways: in Firestore you have stored peopleAttended as an String, you need to make it an integer to work!
Thank you for new lessons 🎉
Very nice tutorial. Thank you!
I have one question. When returning from the QuestionsView, you manually increased peopleAttended += 1 (27:05) locally instead of re-fetching the updated data. How could I do that? run the asynchronous function fetchData in the onFinish of the QuestionView component and update the view?
Thank you in advance!
i got "The data couldn’t be read because it isn’t in the correct format." when running the code (6:05). Instead of showing the title, i get loading image.
Me too had the same issue
Thank you!
Amazing! Thanks 🙌🏻
Awesome!
Question: I want to save the quiz results so user can go back and see them afterwards. When I save / load to userdefaults because of the struct tappedAnswer: String = "" it always loses the users answer. How can I save and load the data keeping the users tappedAnswer?
I figured it out, with init(from decoder: Decoder) throws and self.tappedAnswer = try container.decodeIfPresent(String.self, forKey: .tappedAnswer) ?? ""
Is the full source code in Paterson?
PTreon
@@latinacoder3699 Peterson, Jordan Peterson
@@30guarino 🤣🤣
Thanks for the awesome lesson. In my environment the .data(as: Decodable) option in the Firestore.firestore() object does not exist. I tried using the latest Firebase Version as well as Version 9.6.0 as used in your video. In either version, there is only .data() and .data(with: ServerTimeStampBehaviour). Is .data(as: Decodable) a custom extension?
For everyone who has the same issue as me and wants a fix:
1. Get the data with .data()
let infoData = Firestore.firestore().collection("Quiz").document("Info").getDocument().data()
2. Manually parse the content of infoData onto the Info Model:
let info = Info(title: infoData?["title"] as? String ?? "", peopleAttended: infoData?["peopleAttended"] as? Int ?? 0, rules: infoData?["rules"] as? [String] ?? [])
Do the exact same thing with the questions Object in the .compactMap{} closure
You need to import FirebaseFirestoreSwift for that option; it's in that package.
Hi @@Kavsoft - just checked again - my XCode does not show the data(as:) option :/ I imported FirebaseFirestoreSwift. Maybe it is an issue with my environment. The work around works though for anyone who needs it :) #Learning :P
@@stephansupload9029 import FirebaseFirestore (I had same issues with the FirebaseFirestoreSwift)
Hi can you show the code for questions object? i have same problem with the import not working for me too
Hi @@felixkart233 - sorry to see your issue so late... here is the whole function:
/// - Fetching Quiz Info and Questions
func fetchData() async throws {
try await loginUserAnonymous()
let infoData = try await Firestore.firestore().collection("Quiz").document("Info").getDocument().data()
let info = Info(title: infoData?["title"] as? String ?? "", peopleAttended: infoData?["peopleAttended"] as? Int ?? 0, rules: infoData?["rules"] as? [String] ?? [])
let questions = try await Firestore.firestore().collection("Quiz").document("Info").collection("Questions").getDocuments()
.documents
.compactMap {
let questionData = $0.data()
let question = Question(question: questionData["question"] as? String ?? "", options: questionData["options"] as? [String] ?? [], answer: questionData["answer"] as? String ?? "")
return question
}
/// -. UI Must be updated on Main Thred
await MainActor.run(body: {
self.quizInfo = info
self.questions = questions
})
}
Hi , I tried the code and setup . I am getting this error
2023-05-11 09:59:01.464726-0500 Quiz_App[94732:4426386] 9.6.0 - [GoogleUtilities/AppDelegateSwizzler][I-SWZ001014] App Delegate does not conform to UIApplicationDelegate protocol.
The data couldn’t be read because it isn’t in the correct format.
Could you help me with this. 8:56
did you able to fix the error?
@@honamchow6676 I guess this is a bit late by anyways: in Firestore you have stored peopleAttended as an String, you need to make it an integer to work!