我有一些错误,例如“表达式隐式强制从String?
强制转换为Any
”这是我的代码:
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)
请帮帮我
答案 0 :(得分:37)
print
函数需要一组Any
个参数。 String
是Any
。在这种情况下,Xcode告诉您它隐式地将可选字符串强制转换为Any
对象(通过转换String
中的Optional(value)
值)。
要避免此警告,您只需使用默认值或展开String?
print(user?.email ?? "User instance is nil")
print(user!.email)