> On May 24, 2016, at 1:11 PM, Ryan Lovelett <swift-...@ryan.lovelett.me> wrote: > > On Tue, May 24, 2016, at 04:07 PM, Tony Parker wrote: >> Let’s get a bug into JIRA, then we’ll figure out what we should do here. > > That's the problem for me. What is the bug? Based on the code example I > provided in this thread. I'm somewhat convinced that the bug is that > Foundation on Linux/Glibc is "broken". In that it does not match the behavior > of Foundation on Darwin, yet it has the desired behavior.
What I mean is that I want to track the issue in JIRA so we don’t lose it, and so we can find it later when looking for issues that prevent fully cross-platform behavior. We can look into fixing these in several ways, including adding new API in both frameworks, changing implementations, etc. - Tony > >> >> - Tony >> >>> On May 24, 2016, at 1:03 PM, Jens Alfke <j...@mooseyard.com >>> <mailto:j...@mooseyard.com>> wrote: >>> >>> >>>> On May 24, 2016, at 12:52 PM, Tony Parker <anthony.par...@apple.com >>>> <mailto:anthony.par...@apple.com>> wrote: >>>> >>>> One other possibility is using the objCType property on NSNumber’s >>>> superclass NSValue to check. >>> >>> That doesn’t work, unfortunately, at least not with Apple’s Foundation. >>> NSNumbers initialized with booleans have objcType “c” because `BOOL` is >>> just a typedef for `char`. So the only way to tell a boolean apart from an >>> 8-bit int is to compare the object pointer against the singleton true and >>> false objects. >>> >>> Here’s a snippet of Obj-C code I use for this in my JSON encoder: >>> >>> char ctype = self.objCType[0]; >>> switch (ctype) { >>> case 'c': { >>> // The only way to tell whether an NSNumber with 'char' type is a boolean >>> is to >>> // compare it against the singleton kCFBoolean objects: >>> if (self == (id)kCFBooleanTrue) >>> return yajl_gen_bool(gen, true); >>> else if (self == (id)kCFBooleanFalse) >>> return yajl_gen_bool(gen, false); >>> else >>> return yajl_gen_integer(gen, self.longLongValue); >>> } >>> >>>> I haven’t seen how much of this is implemented in corelibs-foundation yet. >>> >>> I took a peek at the Swift NSNumber and NSValue implementations on Github, >>> and the objcType stuff doesn’t seem to be functional. It looks like >>> objcType will only have a value if the object was initialized as an NSValue >>> with the type code passed in, not if the typical NSNumber initializers were >>> used. >>> >>> —Jens >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users