FirebaseRemoteConfigValueDecoderHelper.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. import FirebaseRemoteConfig
  18. import FirebaseSharedSwift
  19. /// Implement the FirebaseRemoteConfigValueDecoding protocol for the shared Firebase decoder to
  20. /// decode Remote Config Values. It returns the four different kinds of values from
  21. /// a RemoteConfigValue object.
  22. struct FirebaseRemoteConfigValueDecoderHelper: FirebaseRemoteConfigValueDecoding {
  23. let value: RemoteConfigValue
  24. func numberValue() -> NSNumber {
  25. return value.numberValue
  26. }
  27. func boolValue() -> Bool {
  28. return value.boolValue
  29. }
  30. func stringValue() -> String {
  31. return value.stringValue ?? ""
  32. }
  33. func dataValue() -> Data {
  34. return value.dataValue
  35. }
  36. func arrayValue() -> [AnyHashable]? {
  37. guard let value = value.jsonValue as? [AnyHashable] else {
  38. return nil
  39. }
  40. return value
  41. }
  42. func dictionaryValue() -> [String: AnyHashable]? {
  43. guard let value = value.jsonValue as? [String: AnyHashable] else {
  44. return nil
  45. }
  46. return value
  47. }
  48. }