FirebaseRemoteConfigValueDecoderHelper.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2021 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. #if SWIFT_PACKAGE
  18. @_exported import FirebaseRemoteConfigInternal
  19. #endif // SWIFT_PACKAGE
  20. import FirebaseSharedSwift
  21. /// Implement the FirebaseRemoteConfigValueDecoding protocol for the shared Firebase decoder to
  22. /// decode Remote Config Values. It returns the four different kinds of values from
  23. /// a RemoteConfigValue object.
  24. struct FirebaseRemoteConfigValueDecoderHelper: FirebaseRemoteConfigValueDecoding {
  25. let value: RemoteConfigValue
  26. func numberValue() -> NSNumber {
  27. return value.numberValue
  28. }
  29. func boolValue() -> Bool {
  30. return value.boolValue
  31. }
  32. func stringValue() -> String {
  33. return value.stringValue ?? ""
  34. }
  35. func dataValue() -> Data {
  36. return value.dataValue
  37. }
  38. func arrayValue() -> [AnyHashable]? {
  39. guard let value = value.jsonValue as? [AnyHashable] else {
  40. return nil
  41. }
  42. return value
  43. }
  44. func dictionaryValue() -> [String: AnyHashable]? {
  45. guard let value = value.jsonValue as? [String: AnyHashable] else {
  46. return nil
  47. }
  48. return value
  49. }
  50. }