ServiceAuthenticationUI.swift 797 B

123456789101112131415161718192021222324252627282930313233
  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. }
  12. public extension ServiceAuthenticationUI {
  13. var credentials: [(field: ServiceCredential, value: String?)] {
  14. return zip(credentialFormFields, credentialValues).map { (field, value) in
  15. return (field: field, value: value)
  16. }
  17. }
  18. func resetCredentials() {
  19. for (index, field) in credentialFormFields.enumerated() {
  20. credentialValues[index] = field.options?.first?.value
  21. }
  22. reset()
  23. }
  24. }