表达式从“字符串"隐式强制转换去任何 [英] Expression implicitly coerced from 'String?' to Any

查看:175
本文介绍了表达式从“字符串"隐式强制转换去任何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些错误,例如表达式从String?隐式强制为Any",这是我的代码:

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
}

此行中的错误

print(user?.email)

还有

print(error?.localizedDescription)

请帮助我

推荐答案

print函数需要一组Any参数. StringAny.在这种情况下,Xcode告诉您它通过将Optional(value)中的String值转换为隐式将可选字符串强制转换为Any对象.

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)).

为避免此警告,您可以简单地使用默认值或展开String?

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)

这篇关于表达式从“字符串"隐式强制转换去任何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆