Skip to content

Instantly share code, notes, and snippets.

@rtking1993
Created February 8, 2019 11:44
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 rtking1993/a3bec3cc9c1a868bcd5c8482cad5f78e to your computer and use it in GitHub Desktop.
Save rtking1993/a3bec3cc9c1a868bcd5c8482cad5f78e to your computer and use it in GitHub Desktop.
// MARK: LoginViewController
class LoginViewController: UIViewController, AuthenticationSessionDelegate {
func login(with username: String,
password: String) {
let authenticationSession = AuthenticationSession()
authenticationSession.delegate = self
authenticationSession.performLogin(with: username,
password: password)
}
// MARK: AuthenticationSessionDelegate Methods
func authenticationSession(_ authenticationSession: AuthenticationSession, didLoginWith userIdentifier: String) {
// Handle the login with userIdentifier
}
}
// MARK: AuthenticationSessionDelegate
protocol AuthenticationSessionDelegate: class {
func authenticationSession(_ authenticationSession: AuthenticationSession, didLoginWith userIdentifier: String)
}
// MARK: AuthenticationSession
class AuthenticationSession {
var delegate: AuthenticationSessionDelegate?
func performLogin(with username: String,
password: String) {
let userIdentifier = "12345" //Service.login(username, password)
delegate?.authenticationSession(self, didLoginWith: userIdentifier)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment