forked from thoughtbot/Argo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, we were overloading `JSON.Number` to include boolean values. This was done because we believed that there was no way to determine if an `NSNumber` returned from `NSJSONSerialization` was actually a boolean value or not. Turns out, this was incorrect. Under the covers, `NSNumber` is toll-free bridged with `CFNumberRef`. And `CFNumberRef` has a specific implementation for boolean values (`CFBooleanRef`). So we can actually get the type ID for `CFBooleanRef` and just check it against the type ID for `self` and if that returns `true`, then we have a boolean value and can handle it accordingly.
- Loading branch information
Showing
4 changed files
with
39 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
|
||
extension NSNumber { | ||
var isBool: Bool { | ||
return CFBooleanGetTypeID() == CFGetTypeID(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters