UserProtocols.swift 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Protocols.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/8/11.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. func == (lhs: ValidationResult, rhs: ValidationResult) -> Bool {
  10. switch (lhs, rhs) {
  11. case (.ok, .ok):
  12. return true
  13. case (.empty, .empty):
  14. return true
  15. case (.validating, .validating):
  16. return true
  17. case (.failed, .failed):
  18. return true
  19. default:
  20. return false
  21. }
  22. }
  23. enum ValidationResult: CustomStringConvertible, Equatable {
  24. case ok
  25. case empty
  26. case validating
  27. case failed(message: String)
  28. var description: String {
  29. switch self {
  30. case .ok:
  31. return ""
  32. case .empty:
  33. return ""
  34. case .validating:
  35. return "validating ..."
  36. case let .failed(message):
  37. return message
  38. }
  39. }
  40. }
  41. protocol UserValidationService {
  42. func validateUsername(_ username: String) -> ValidationResult
  43. func validatePassword(_ password: String) -> ValidationResult
  44. }