質問: error { print("an error occurred while signing in!! \(error)") return } print("user is signed in with facebook!") facebookhelper.getprofileinfo(completion: { (name, pictureurl) in firebasehelper.setuser(user: user!, name: name, profileurl: pictureurl, completion: { self.performsegue(withidentifier: "facebookloggedinsegue", sender: nil) }) }) } これに取り組むより良い方法はありますか?そのようなものがobserve関数にネストされていると、混乱するだけです。
回答: あなたはこのようなものを試すことができます: func signin(email: string, password: string) -> user? { var user: user? = nil dispatchqueue.global().async { let semaphore = dispatchsemaphore(value: 0) auth.auth().signin(withemail: email, password: password) { (firuser, error) in if let firuser = firuser { user = user(id: firuser.uid, email: firuser.email, nickname: firuser.displayname) } semaphore.signal() } _ = semaphore.wait(timeout: .distantfuture) } return user } 次のように使用します。if let user = self.authservice.signin(email: request.email, password: request.password) { print(user) }