@@ -44,46 +44,22 @@ public enum RemoteConfigCodableError: Error {
44
44
}
45
45
46
46
public extension RemoteConfig {
47
- /// Decodes the given type from the respective Remote Config values.
47
+ /// Decodes a struct from the respective Remote Config values.
48
48
///
49
49
/// - Parameter asType: The type to decode to.
50
- /// - Throws: An error if the decoding fails.
51
- /// - Returns: The decoded value; otherwise, an error if one occurred.
52
50
func decoded< Value: Decodable > ( asType: Value . Type = Value . self) throws -> Value {
53
- try decoded ( asType: asType, decoder: FirebaseDataDecoder ( ) )
54
- }
55
-
56
- /// Decodes the given type from the respective Remote Config values.
57
- /// - Parameters:
58
- /// - asType: The type to decode to.
59
- /// - decoder: The encoder to use to decode the given type.
60
- /// - Throws: An error if the decoding fails.
61
- /// - Returns: The decoded value; otherwise, an error if one occurred.
62
- func decoded< Value: Decodable > ( asType: Value . Type = Value . self,
63
- decoder: FirebaseDataDecoder ) throws -> Value {
64
51
let keys = allKeys ( from: RemoteConfigSource . default) + allKeys( from: RemoteConfigSource . remote)
65
52
let config = keys. reduce ( into: [ String: FirebaseRemoteConfigValueDecoderHelper] ( ) ) {
66
53
$0 [ $1] = FirebaseRemoteConfigValueDecoderHelper ( value: configValue ( forKey: $1) )
67
54
}
68
- return try decoder . decode ( Value . self, from: config)
55
+ return try FirebaseDataDecoder ( ) . decode ( Value . self, from: config)
69
56
}
70
57
71
58
/// Sets config defaults from an encodable struct.
72
59
///
73
60
/// - Parameter value: The object to use to set the defaults.
74
- /// - Throws: An error if the encoding fails.
75
61
func setDefaults< Value: Encodable > ( from value: Value ) throws {
76
- try setDefaults ( from: value, encoder: FirebaseDataEncoder ( ) )
77
- }
78
-
79
- /// Sets config defaults from an encodable struct.
80
- /// - Parameters:
81
- /// - value: The object to use to set the defaults.
82
- /// - encoder: The encoder to use to encode the given object.
83
- /// - Throws: An error if the encoding fails.
84
- func setDefaults< Value: Encodable > ( from value: Value ,
85
- encoder: FirebaseDataEncoder ) throws {
86
- guard let encoded = try encoder. encode ( value) as? [ String : NSObject ] else {
62
+ guard let encoded = try FirebaseDataEncoder ( ) . encode ( value) as? [ String : NSObject ] else {
87
63
throw RemoteConfigCodableError . invalidSetDefaultsInput (
88
64
" The setDefaults input: \( value) , must be a Struct that encodes to a Dictionary "
89
65
)
0 commit comments