Expression implicitly coerced from 'String?' to Any

SwiftStringOptional

Swift Problem Overview


I have some error like this "Expression implicitly coerced from String? to Any" this is my code :

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    FIRApp.configure()
    FIRAuth.auth()?.signIn(withEmail: "[email protected]", password: "mypassword", completion: { (user, error) in
        if (error != nil) {
            print(user?.email)
        }else {
            print(error?.localizedDescription)
        }
    })
    
    return true
}

Error in this line

print(user?.email)

And

print(error?.localizedDescription)

Please help me

Swift Solutions


Solution 1 - Swift

The print function requires a set of Any parameters. String is a Any. In this case Xcode is telling you that it implicitly coerced the optional string into an Any object (by transforming the String value in Optional(value)).

To avoid this warning, you can simply use a default value or unwrap the String?

print(user?.email ?? "User instance is nil")
print(user!.email)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDewangga Arie BaskaraView Question on Stackoverflow
Solution 1 - SwiftLuca D'AlbertiView Answer on Stackoverflow