2016-11-19 21 views
17

私はこのようなエラーがあります。「式は暗黙のうちに 'String?どれに」これが私のコードです:'String?'から暗黙的に強制的に表現されます。 to Any Any

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 
} 

この行でエラーが発生しました

 print(user?.email) 

そして

print(error?.localizedDescription) 

くれ

答えて

18

を助けてくださいprint機能がAnyパラメータのセットが必要です。 StringAnyです。この場合、Xcodeは、Stringの値をOptional(value)に変換することによって、暗黙的にオプションの文字列をAnyオブジェクトに強制的に強制していることを伝えています。

は、この警告を回避するには、単にデフォルト値を使用するか、二行目に String?

​​
+0

ユーザーは何が起こるだろうではありnilをアンラップすることができますか? – probrandono

+2

もちろん、アプリはクラッシュします。しかし、オプションについての私の説明の後、私はそれが暗黙的だと思う –

関連する問題