私はしばらくの間、迅速なコースに従っていて、オンラインツーツと一緒にいます。私が見つけることができた問題のほとんどは、私はこの1つでいくつかの助けを使用することができます。我々はFirebase FIRAuth経由でログインしているユーザのために発生する可能性がエラーを処理しているアプリでタイプの値にはメンバーがいません
、私のコードは次のようになります。
:で、私が最初にFUNCでエラーを取得するコンパイルでclass AuthService {
private static let _instance = AuthService()
static var instance: AuthService {
return _instance
}
func login(email: String, password: String, onComplete: Completion?) {
FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: {(user, error) in
if error != nil {
if let errorCode = FIRAuthErrorCode(rawValue: error!.code) {
if errorCode == .errorCodeUserNotFound {
FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: {(user, error) in
if error != nil {
self.handleFirebaseError(error: error!, onComplete: onComplete)
} else {
if user?.uid != nil {
//Sign in
FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: {(user, error)
in
if error != nil {
self.handleFirebaseError(error: error!, onComplete: onComplete)
} else {
onComplete?(errMsg: nil, data: user)
}
})
}
}
})
}
} else {
self.handleFirebaseError(error: error!, onComplete: onComplete)
}
} else {
onComplete?(errMsg: nil, data: user)
}
})
}
func handleFirebaseError(error: NSError, onComplete: Completion?) {
print(error.debugDescription)
if let errorCode = FIRAuthErrorCode(rawValue: error.code) {
switch(errorCode) {
case .errorCodeInvalidEmail:
onComplete?(errMsg: "Invalid email adress", data: nil)
break
case .errorCodeWrongPassword:
onComplete?(errMsg: "Invalid password", data: nil)
break
case .errorCodeEmailAlreadyInUse, .errorCodeAccountExistsWithDifferentCredential:
onComplete?(errMsg: "Email already in use", data: nil)
break
default:
onComplete?(errMsg: "There was a problem authenticating, try again", data: nil)
break
}
}
if let errorCode = FIRAuthErrorCode(rawValue: error!.code)
「タイプの値 'Error'にメンバーのコードがありません」と言っています。 2番目の関数は、まったく同じ行のコードを使用しますが、エラーはありません。私はアンラップのようなものや成功していないものなど、あらゆる種類のものを試しました。
たとえば、0を追加するとコードはコンパイルできますが、エラーが発生するとすぐにコースが終了します。
ありがとうございました!
私はfirebaseに精通していませんが、コンパイルエラーがある場所の 'error'は2番目の関数の' error'と同じ型(別名NSError)ですか?私はfirebaseがNSErrorではなく独自のエラータイプを返す気がします...(ブロックパラメータリストでタイプが省略されているので、私は言うことができません) – Fonix
Firebaseは実際にそれ自身のエラーコードのリストを持っていますFirebaseのエラータイプを取得しています。これはすべてIntでなければなりません。 両方の関数でエラーの種類が異なるのはなぜか教えてください。 – Takis