Skip to content

Commit c62a45a

Browse files
bsneedBrandon Sneed
andauthored
Renamed mapKeys to mapTransform (#52)
Co-authored-by: Brandon Sneed <brandon.sneed@segment.com>
1 parent 7d02cb7 commit c62a45a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Sources/Segment/Events.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension Analytics {
155155
/// but want to record traits, you should pass nil. For more information on how we
156156
/// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids
157157
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
158-
public func identify(userId: String, traits: [String: AnyHashable]? = nil) {
158+
public func identify(userId: String, traits: [String: Any]? = nil) {
159159
do {
160160
if let traits = traits {
161161
let traits = try JSON(traits as Any)
@@ -178,7 +178,7 @@ extension Analytics {
178178
/// - screenTitle: The title of the screen being tracked.
179179
/// - category: A category to the type of screen if it applies.
180180
/// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc.
181-
public func screen(screenTitle: String, category: String? = nil, properties: [String: AnyHashable]? = nil) {
181+
public func screen(screenTitle: String, category: String? = nil, properties: [String: Any]? = nil) {
182182
var event = ScreenEvent(screenTitle: screenTitle, category: category, properties: nil)
183183
if let properties = properties {
184184
do {
@@ -195,7 +195,7 @@ extension Analytics {
195195
/// - Parameters:
196196
/// - groupId: A unique identifier for the group identification in your system.
197197
/// - traits: Traits of the group you may be interested in such as email, phone or name.
198-
public func group(groupId: String, traits: [String: AnyHashable]?) {
198+
public func group(groupId: String, traits: [String: Any]?) {
199199
var event = GroupEvent(groupId: groupId)
200200
if let traits = traits {
201201
do {

Sources/Segment/ObjC/ObjCAnalytics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension ObjCAnalytics {
5353
/// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids
5454
/// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc.
5555
@objc(identify:traits:)
56-
public func identify(userId: String, traits: [String: AnyHashable]?) {
56+
public func identify(userId: String, traits: [String: Any]?) {
5757
analytics.identify(userId: userId, traits: traits)
5858
}
5959

@@ -79,7 +79,7 @@ extension ObjCAnalytics {
7979
/// - category: A category to the type of screen if it applies.
8080
/// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc.
8181
@objc(screen:category:properties:)
82-
public func screen(screenTitle: String, category: String?, properties: [String: AnyHashable]?) {
82+
public func screen(screenTitle: String, category: String?, properties: [String: Any]?) {
8383
analytics.screen(screenTitle: screenTitle, category: category, properties: properties)
8484
}
8585

@@ -96,7 +96,7 @@ extension ObjCAnalytics {
9696
/// - groupId: A unique identifier for the group identification in your system.
9797
/// - traits: Traits of the group you may be interested in such as email, phone or name.
9898
@objc(group:traits:)
99-
public func group(groupId: String, traits: [String: AnyHashable]?) {
99+
public func group(groupId: String, traits: [String: Any]?) {
100100
analytics.group(groupId: groupId, traits: traits)
101101
}
102102
}

Sources/Segment/Utilities/JSON.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ extension JSON {
274274
/// - Parameters:
275275
/// - keys: A dictionary containing key mappings, in the format of ["Old": "New"].
276276
/// - 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 {
278278
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)
280280
let result = try JSON(mapped)
281281
return result
282282
}
@@ -285,7 +285,7 @@ extension JSON {
285285
// MARK: - Helpers
286286

287287
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] {
289289
let mapped = Dictionary(uniqueKeysWithValues: self.map { key, value -> (Key, Value) in
290290
var newKey = key
291291
var newValue = value
@@ -299,7 +299,7 @@ extension Dictionary where Key == String, Value == Any {
299299
}
300300
// is this value a dictionary?
301301
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) {
303303
// if so, lets recurse...
304304
newValue = r
305305
}
@@ -309,7 +309,7 @@ extension Dictionary where Key == String, Value == Any {
309309
newValue = arrayValue.map { item -> Value in
310310
var newValue = item
311311
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) {
313313
newValue = r
314314
}
315315
}
@@ -318,7 +318,7 @@ extension Dictionary where Key == String, Value == Any {
318318
}
319319

320320
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.
322322

323323
// note: if it's an array, we've processed any dictionaries inside
324324
// already, but this gives the opportunity to apply a transform to the other

Tests/Segment-Tests/JSON_Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class JSONTests: XCTestCase {
137137

138138
let json = try! JSON(dict)
139139

140-
let output = try! json.mapKeys(keys).dictionaryValue
140+
let output = try! json.mapTransform(keys).dictionaryValue
141141

142142
XCTAssertTrue(output!["AKey1"] as! Int == 1)
143143
XCTAssertTrue(output!["AKey2"] as! Int == 2)
@@ -153,7 +153,7 @@ class JSONTests: XCTestCase {
153153

154154
let json = try! JSON(dict)
155155

156-
let output = try! json.mapKeys(keys, valueTransform: { key, value in
156+
let output = try! json.mapTransform(keys, valueTransform: { key, value in
157157
var newValue = value
158158
if let v = newValue as? Int {
159159
if v == 1 {

0 commit comments

Comments
 (0)