Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: LoginViewController
- class LoginViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- NotificationCenter.default.addObserver(self,
- selector: #selector(handleLogin(notification:)),
- name: Notification.Name("UserIdentifier"),
- object: nil)
- }
- func login(with username: String,
- password: String) {
- let authenticationSession = AuthenticationSession()
- authenticationSession.performLogin(with: username,
- password: password)
- }
- @objc func handleLogin(notification: Notification) {
- if let userInfo = notification.userInfo {
- if let userIdentifier = userInfo["User Identifier"] as? String {
- // Handle the login with userIdentifier
- }
- }
- }
- }
- // MARK: AuthenticationSession
- class AuthenticationSession {
- func performLogin(with username: String,
- password: String) {
- let userIdentifier = "12345" //Service.login(username, password)
- NotificationCenter.default.post(name: Notification.Name("UserIdentifier"), object: self, userInfo: ["User Identifier": userIdentifier])
- }
- }
Add Comment
Please, Sign In to add comment