Retrieve Boolean array from Firebase

倖福魔咒の 提交于 2020-01-15 07:46:32

问题


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?

来源:https://stackoverflow.com/questions/42058444/retrieve-boolean-array-from-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!