Expression implicitly coerced from 'String?' to Any [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-30 01:34:25

问题


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: "myemail@gmail.com", 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


回答1:


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)


来源:https://stackoverflow.com/questions/40691184/expression-implicitly-coerced-from-string-to-any

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