Skip to content

Commit ec29695

Browse files
authored
[Config] Split Codable APIs up and improve doc comments (#14552)
1 parent c7ceee4 commit ec29695

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

FirebaseRemoteConfig/Swift/Codable.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,23 @@ public enum RemoteConfigCodableError: Error {
4444
}
4545

4646
public extension RemoteConfig {
47-
/// Decodes a struct from the respective Remote Config values.
47+
/// Decodes the given type from the respective Remote Config values.
4848
///
4949
/// - 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+
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.
5062
func decoded<Value: Decodable>(asType: Value.Type = Value.self,
51-
decoder: FirebaseDataDecoder = .init()) throws -> Value {
63+
decoder: FirebaseDataDecoder) throws -> Value {
5264
let keys = allKeys(from: RemoteConfigSource.default) + allKeys(from: RemoteConfigSource.remote)
5365
let config = keys.reduce(into: [String: FirebaseRemoteConfigValueDecoderHelper]()) {
5466
$0[$1] = FirebaseRemoteConfigValueDecoderHelper(value: configValue(forKey: $1))
@@ -59,8 +71,18 @@ public extension RemoteConfig {
5971
/// Sets config defaults from an encodable struct.
6072
///
6173
/// - Parameter value: The object to use to set the defaults.
74+
/// - Throws: An error if the encoding fails.
75+
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.
6284
func setDefaults<Value: Encodable>(from value: Value,
63-
encoder: FirebaseDataEncoder = .init()) throws {
85+
encoder: FirebaseDataEncoder) throws {
6486
guard let encoded = try encoder.encode(value) as? [String: NSObject] else {
6587
throw RemoteConfigCodableError.invalidSetDefaultsInput(
6688
"The setDefaults input: \(value), must be a Struct that encodes to a Dictionary"

0 commit comments

Comments
 (0)