@@ -274,9 +274,9 @@ extension JSON {
274
274
/// - Parameters:
275
275
/// - keys: A dictionary containing key mappings, in the format of ["Old": "New"].
276
276
/// - valueTransform: An optional value transform closure. Key represents the new key name.
277
- public func mapKeys ( _ keys: [ String : String ] , valueTransform: ( ( _ key: String , _ value: Any ) -> Any ) ? = nil ) throws -> JSON {
277
+ public func mapTransform ( _ keys: [ String : String ] , valueTransform: ( ( _ key: String , _ value: Any ) -> Any ) ? = nil ) throws -> JSON {
278
278
guard let dict = self . dictionaryValue else { return self }
279
- let mapped = try dict. mapKeys ( keys, valueTransform: valueTransform)
279
+ let mapped = try dict. mapTransform ( keys, valueTransform: valueTransform)
280
280
let result = try JSON ( mapped)
281
281
return result
282
282
}
@@ -285,7 +285,7 @@ extension JSON {
285
285
// MARK: - Helpers
286
286
287
287
extension Dictionary where Key == String , Value == Any {
288
- internal func mapKeys ( _ keys: [ String : String ] , valueTransform: ( ( _ key: Key , _ value: Value ) -> Any ) ? = nil ) throws -> [ Key : Value ] {
288
+ internal func mapTransform ( _ keys: [ String : String ] , valueTransform: ( ( _ key: Key , _ value: Value ) -> Any ) ? = nil ) throws -> [ Key : Value ] {
289
289
let mapped = Dictionary ( uniqueKeysWithValues: self . map { key, value -> ( Key , Value ) in
290
290
var newKey = key
291
291
var newValue = value
@@ -299,7 +299,7 @@ extension Dictionary where Key == String, Value == Any {
299
299
}
300
300
// is this value a dictionary?
301
301
if let dictValue = value as? [ Key : Value ] {
302
- if let r = try ? dictValue. mapKeys ( keys, valueTransform: valueTransform) {
302
+ if let r = try ? dictValue. mapTransform ( keys, valueTransform: valueTransform) {
303
303
// if so, lets recurse...
304
304
newValue = r
305
305
}
@@ -309,7 +309,7 @@ extension Dictionary where Key == String, Value == Any {
309
309
newValue = arrayValue. map { item -> Value in
310
310
var newValue = item
311
311
if let dictValue = item as? [ Key : Value ] {
312
- if let r = try ? dictValue. mapKeys ( keys, valueTransform: valueTransform) {
312
+ if let r = try ? dictValue. mapTransform ( keys, valueTransform: valueTransform) {
313
313
newValue = r
314
314
}
315
315
}
@@ -318,7 +318,7 @@ extension Dictionary where Key == String, Value == Any {
318
318
}
319
319
320
320
if !( newValue is [ Key : Value ] ) , let transform = valueTransform {
321
- // it's not a dictionary apply our transform.
321
+ // it's not a dictionary so apply our transform.
322
322
323
323
// note: if it's an array, we've processed any dictionaries inside
324
324
// already, but this gives the opportunity to apply a transform to the other
0 commit comments