Build a Quiz App With SwiftUI - Firebase - Xcode 14 - SwiftUI Tutorials

Поділитися
Вставка
  • Опубліковано 11 жов 2024

КОМЕНТАРІ • 25

  • @andrejkling3886
    @andrejkling3886 Рік тому +1

    Thank you for new lessons 🎉

  • @codingwithrudy
    @codingwithrudy Рік тому

    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!

  • @honamchow6676
    @honamchow6676 10 місяців тому +1

    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.

    • @iYousef911
      @iYousef911 6 місяців тому

      Me too had the same issue

  • @sraldous
    @sraldous Рік тому

    Thank you!

  • @OscarShimada
    @OscarShimada Рік тому

    Amazing! Thanks 🙌🏻

  • @李子杰-d2j
    @李子杰-d2j Рік тому

    Awesome!

  • @sraldous
    @sraldous Рік тому

    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?

    • @sraldous
      @sraldous Рік тому

      I figured it out, with init(from decoder: Decoder) throws and self.tappedAnswer = try container.decodeIfPresent(String.self, forKey: .tappedAnswer) ?? ""

  • @latinacoder3699
    @latinacoder3699 Рік тому

    Is the full source code in Paterson?

  • @stephansupload9029
    @stephansupload9029 Рік тому +2

    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

    • @Kavsoft
      @Kavsoft  Рік тому

      You need to import FirebaseFirestoreSwift for that option; it's in that package.

    • @stephansupload9029
      @stephansupload9029 Рік тому

      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

    • @sraldous
      @sraldous Рік тому

      @@stephansupload9029 import FirebaseFirestore (I had same issues with the FirebaseFirestoreSwift)

    • @felixkart233
      @felixkart233 Рік тому

      Hi can you show the code for questions object? i have same problem with the import not working for me too

    • @stephansupload9029
      @stephansupload9029 Рік тому

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

  • @SaiNithisha
    @SaiNithisha Рік тому

    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
      @honamchow6676 10 місяців тому

      did you able to fix the error?

    • @highlights8278
      @highlights8278 5 місяців тому

      @@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!