Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample code not working, setValue wrong? #49

Open
hixfield opened this issue Jul 26, 2018 · 2 comments
Open

sample code not working, setValue wrong? #49

hixfield opened this issue Jul 26, 2018 · 2 comments

Comments

@hixfield
Copy link

hixfield commented Jul 26, 2018

If I use the sample code it crashes with "Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(nodeFrom:priority:) Cannot store object of type _SwiftValue at . Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray."

 struct Test: Encodable {
        var integer = Int(10)
        var string  = String("test")
    }

    func writeToFirebase(uid: String, completion: ( (Error?, DatabaseReference?)->() )? = nil ) {
        do {
            let data = try toFirebaseData() as [AnyHashable: Any]
            log.debug("\(data)")
            
            var t = Test()
            firebaseRef(uid: uid).setValue(try FirebaseEncoder().encode(t)) {
                (error, reference) in
                completion?(error, reference)
            }
        } catch let error {
            completion?(error, nil)
        }
    }

I believe the usage of setValue is wrong, if I change it to updateChildValues is works perfectly.
However, issue is that updateChildeValues will not replace the whole data under the key which I need (and that is why I wanted to use setValue).

@antonijap
Copy link

antonijap commented Aug 3, 2018

Well, Firestore documentation is a bit different.

FirestoreManager.shared.db.collection("data").getDocuments { documents, error in
           if let documents = documents {
               for document in documents.documents {
                   guard let model = try? FirestoreDecoder().decode(Model.self, from: document.data()) else { print("Error"); return }
                   print("Model: \(model.name), \(model.email), \(model.location), \(model.details.dealbreakers)")
               }
           } else {
               print("Document does not exist")
           }
}

@hixfield
Copy link
Author

hixfield commented Aug 3, 2018

Don’t understand can you ellaborate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants