Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast from 'FIRRemoteConfigValue!' to unrelated type 'String' always fails

I have about 50 of this same warning in my project. Since updating, all of my functions where I call snapshot.value["something"] as! String are failing. They all used to work before. I'm not even using the RemoteConfig feature. I just want to retrieve data.

Example from my User class:

init(snapshot: FIRDataSnapshot) {
        firstName = snapshot.value!["firstName"] as! String
        lastName = snapshot.value!["lastName"] as! String
}

Example from a function (I can give more examples but its basically more of the same):

func loadProfileImage(ref:FIRDatabaseReference) {
        ref.observeEventType(.Value, withBlock: {snapshot in
            let base64String = snapshot.value!["profileImgURL"] as! String
            let decodedData = NSData(base64EncodedString: base64String, options:NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
            if let decodedImage = UIImage(data: decodedData!) {
                self.profileImgImageView.contentMode = .ScaleAspectFill
                self.profileImgImageView.layer.cornerRadius = self.profileImgImageView.frame.size.width / 2
                self.profileImgImageView.clipsToBounds = true
                self.profileImgImageView.image = decodedImage as UIImage
            }
        })
    }

The app runs because they are just warnings but the warnings are correct because the app fails as soon as it tries to retrieve any data.

like image 286
Michael Williams Avatar asked May 19 '16 23:05

Michael Williams


2 Answers

So apparently having the Firebase/RemoteConfig pod causes this error. As soon as I uninstalled the pod, the warning went away. Definitely putting this in as a bug.

like image 144
Michael Williams Avatar answered Oct 21 '22 17:10

Michael Williams


I have faced same issue, Below code work me perfectely.

Use valueForKey Instead of [] bracket access value

Then all value goes away...

For Example

Below code give a warning...

 let someArray = resource["someArrayKey"] as? NSArray
 let someBool = resource["someBoolKey"] as? Bool

Use below code

 let someArray = resource.valueForKey("someArrayKey") as? NSArray
 let someBool = resource.valueForKey("someBoolKey") as? Bool
like image 30
Hitesh Surani Avatar answered Oct 21 '22 19:10

Hitesh Surani