ServiceAuthenticationUI.swift 915 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // ServiceAuthenticationUI.swift
  3. // LoopKitUI
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import LoopKit
  8. public protocol ServiceAuthenticationUI: ServiceAuthentication {
  9. // The indexed credentials (e.g. username, password) used to authenticate
  10. var credentialFormFields: [ServiceCredential] { get }
  11. //Form field helper text displayed when completing form
  12. var credentialFormFieldHelperMessage: String? { get }
  13. }
  14. public extension ServiceAuthenticationUI {
  15. var credentials: [(field: ServiceCredential, value: String?)] {
  16. return zip(credentialFormFields, credentialValues).map { (field, value) in
  17. return (field: field, value: value)
  18. }
  19. }
  20. func resetCredentials() {
  21. for (index, field) in credentialFormFields.enumerated() {
  22. credentialValues[index] = field.options?.first?.value
  23. }
  24. reset()
  25. }
  26. }