Skip to content

Commit 4379a77

Browse files
authored
Merge pull request #21 from mixpanel/fix-bool-value
Fix the bool value being tracked as Int
2 parents b5b3587 + 06299c6 commit 4379a77

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ios/Classes/MixpanelTypeHandler.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
case let value as String:
99
return value as MixpanelType
1010

11+
case let value as NSNumber:
12+
if isBoolNumber(value) {
13+
return value.boolValue as MixpanelType
14+
} else if isInvalidNumber(value) {
15+
return String(describing: value) as MixpanelType
16+
} else {
17+
return value as MixpanelType
18+
}
19+
1120
case let value as Int:
1221
return value as MixpanelType
1322

@@ -42,6 +51,18 @@
4251
return nil
4352
}
4453
}
54+
55+
private static func isBoolNumber(_ num: NSNumber) -> Bool
56+
{
57+
let boolID = CFBooleanGetTypeID()
58+
let numID = CFGetTypeID(num)
59+
return numID == boolID
60+
}
61+
62+
private static func isInvalidNumber(_ num: NSNumber) -> Bool
63+
{
64+
return num.doubleValue.isInfinite || num.doubleValue.isNaN
65+
}
4566

4667
static func mixpanelProperties(properties: Dictionary<String, Any>? = nil, mixpanelProperties: Dictionary<String, Any>? = nil) -> Dictionary<String, MixpanelType> {
4768
var properties = (properties != nil) ? properties : [:]

0 commit comments

Comments
 (0)