2

Retrieving a Boolean array from a snapshot from Firebase gives me 0's and 1's. What is the best way to store an Boolean array from Firebase to an array in my project?

This is my code:

func loadUpInformation()
    {
        print("loading data")
        let user = FIRAuth.auth()?.currentUser
        let userID = FIRAuth.auth()?.currentUser?.uid
        ref = FIRDatabase.database().reference()
        ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
            if !snapshot.exists() { return }
            if let achievementsUnlockedFirebase = snapshot.childSnapshot(forPath: "/AchievementsUnlocked").value
            {
            // ????
            }
        })

    }

I already tried:

Read Data from Firebase and Save Into an Array (Swift)

        if let AchievementsUnlockedFirebase = snapshot.childSnapshot(forPath: "/AchievementsUnlocked").value as? Bool
        {
            print("snapshot exist")
            achievementsUnlocked.append(AchievementsUnlockedFirebase)
            print(AchievementsUnlockedFirebase)
            print(achievementsUnlocked)
        }

doesn't give me a print, changing as? String to as? Bool has the same result. Removing the "as? String" gives me an output, these are the 0's and 1's. Therefore I could use as? Int but then I need to convert it to Booleans. I tried it with a for in loop, but then I get the error cannot convert type to Sequence.

How can I convert a Boolean array in Firebase to a Boolean array in Swift?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.