Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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