Skip to content

Instantly share code, notes, and snippets.

@MartinP7r
Last active June 24, 2018 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinP7r/1999daab25c23b5440dc24839ff3f653 to your computer and use it in GitHub Desktop.
Save MartinP7r/1999daab25c23b5440dc24839ff3f653 to your computer and use it in GitHub Desktop.
medium_post_05
class GoogleSignInService: NSObject, SignInService, GIDSignInDelegate, GIDSignInUIDelegate {
// intermediary closure to be called when sign-in finishes
var signedIn: ((String) -> Void)?
func setup() { /* (...) */ }
func signIn(_ completion: @escaping (String) -> Void) {
// hand own completion block to intermediary closure
signedIn = { token in
completion(token)
}
GIDSignIn.sharedInstance().signIn()
}
func sign(_ signIn: GIDSignIn!,
didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error == nil {
// call intermediary closure with token
signedIn?(user.authentication.idToken)
}
}
func signOut() { /* (...) */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment