Guest User

Untitled

a guest
Feb 9th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. // MARK: LoginViewController
  2.  
  3. class LoginViewController: UIViewController {
  4.  
  5. override func viewDidLoad() {
  6. super.viewDidLoad()
  7.  
  8. NotificationCenter.default.addObserver(self,
  9. selector: #selector(handleLogin(notification:)),
  10. name: Notification.Name("UserIdentifier"),
  11. object: nil)
  12. }
  13.  
  14. func login(with username: String,
  15. password: String) {
  16. let authenticationSession = AuthenticationSession()
  17. authenticationSession.performLogin(with: username,
  18. password: password)
  19. }
  20.  
  21. @objc func handleLogin(notification: Notification) {
  22. if let userInfo = notification.userInfo {
  23. if let userIdentifier = userInfo["User Identifier"] as? String {
  24. // Handle the login with userIdentifier
  25. }
  26. }
  27. }
  28. }
  29.  
  30. // MARK: AuthenticationSession
  31.  
  32. class AuthenticationSession {
  33.  
  34. func performLogin(with username: String,
  35. password: String) {
  36. let userIdentifier = "12345" //Service.login(username, password)
  37. NotificationCenter.default.post(name: Notification.Name("UserIdentifier"), object: self, userInfo: ["User Identifier": userIdentifier])
  38. }
  39. }
Add Comment
Please, Sign In to add comment