0
votes

When I run the program and change a value and send it to Firebase, I get the error: Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(updateChildValues:withCompletionBlock:) Cannot store object of type UITextField at . Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'

func updateUsersProfile() {
    //check to see if the user is logged in
    if let userID = Auth.auth().currentUser?.uid {
        //create an access point the Firebase storage
        let storageItem = storageRef.child("profile_images").child(userID)
        //get the image uploaded from photo library
        guard let image = profileImageView.image else { return }
        if let newImage = image.pngData() {
            //upload to Firebase storage
            storageItem.putData(newImage, metadata: nil, completion: {
                (metadata, error) in
                if error != nil {
                    print(error!)
                    return
                }
                storageItem.downloadURL(completion: { (url, error) in
                    if error != nil {
                        print(error!)
                        return
                    }
                    if let profilePhotoURL = url?.absoluteString {
                        guard let newUserName = self.usernameText.text else { return }
                        guard let newDisplayName = self.displayNameText.text else { return }
                        guard let newBioText = self.bioText.text else { return }
                        guard let newDescription = self.descriptionText else { return }

                        let newValuesForProfile =
                            ["photo": profilePhotoURL,
                             "username": newUserName,
                             "displayname": newDisplayName,
                             "mydescription": newDescription,
                             "bio": newBioText]

                        //Update the Firebase database for that user
                        self.databaseRef.child("profile").child(userID).updateChildValues(newValuesForProfile, withCompletionBlock: { (error, ref) in
                            if error != nil {
                                print(error!)
                                return
                            }
                            print("Profile successfully updated")
                        })
                    }
                })
            })
        }
    }
1
Hi, Put all the values as String - ["photo": "(profilePhotoURL)", and so on - Yogesh Tandel

1 Answers

0
votes

error: Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(updateChildValues:withCompletionBlock:) Cannot store object of type UITextField at . Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'

Error states that function updateChildValues:withCompletionBlock is trying to store some object of type UITextField rather than text. So you should check if you wrote some text-field itself rather than text-field's text.

On examining, you will found out that you have added descriptionText to the dictionary rather than text. Change the line as:

guard let newDescription = self.descriptionText.text else { return }