<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 24, 2016, at 1:11 PM, Ryan Lovelett &lt;<a href="mailto:swift-dev@ryan.lovelett.me" class="">swift-dev@ryan.lovelett.me</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">


<title class=""></title>

<div class=""><div class="">On Tue, May 24, 2016, at 04:07 PM, Tony Parker wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">Let’s get a bug into JIRA, then we’ll figure out what we should do here.<br class=""></div>
</blockquote><div class="">&nbsp;</div>
<div class="">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.</div></div></div></blockquote><div><br class=""></div>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.</div><div><br class=""></div><div>- Tony</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="">
<div class="">&nbsp;</div>
<blockquote type="cite" class=""><div class="">&nbsp;</div>
<div class="">- Tony<br class=""></div>
<div class=""><div class="">&nbsp;</div>
<div class=""><div class=""><blockquote type="cite" class=""><div class="">On May 24, 2016, at 1:03 PM, Jens Alfke &lt;<a href="mailto:jens@mooseyard.com" class="">jens@mooseyard.com</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div style="word-wrap:break-word;-webkit-line-break:after-white-space;" class=""><div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On May 24, 2016, at 12:52 PM, Tony Parker &lt;<a href="mailto:anthony.parker@apple.com" class="">anthony.parker@apple.com</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div style="font-family:Alegreya-Regular;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" class="">One other possibility is using the objCType property on NSNumber’s superclass NSValue to check.<br class=""></div>
</div>
</blockquote><div class="">&nbsp;</div>
<div class="">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.<br class=""></div>
</div>
</div>
</div>
</blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word;-webkit-line-break:after-white-space;" class=""><div class=""><div class="">&nbsp;</div>
<div class="">Here’s a snippet of Obj-C code I use for this in my JSON encoder:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">char</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> ctype = </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">self</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">.</span><span class="colour" style="color:rgb(112, 61, 170)"><b class="">objCType</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">[</span><span class="colour" style="color:rgb(66, 66, 66)">0</span><span style="font-variant-ligatures:no-common-ligatures;" class="">];</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">switch</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> (ctype) {</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">case</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(121, 121, 121)">'c'</span><span style="font-variant-ligatures:no-common-ligatures;" class="">: {</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;color:rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;" class=""><i class="">// The only way to tell whether an NSNumber with 'char' type is a boolean is to</i></span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;color:rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;" class=""><i class="">// compare it against the singleton kCFBoolean objects:</i></span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">if</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> (</span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">self</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> == (</span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">id</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">)</span><span class="colour" style="color:rgb(112, 61, 170)"><b class="">kCFBooleanTrue</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">)</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">return</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(52, 56, 147)">yajl_gen_bool</span><span style="font-variant-ligatures:no-common-ligatures;" class="">(gen, </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">true</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">);</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">else</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">if</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> (</span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">self</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> == (</span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">id</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">)</span><span class="colour" style="color:rgb(112, 61, 170)"><b class="">kCFBooleanFalse</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">)</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">return</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(52, 56, 147)">yajl_gen_bool</span><span style="font-variant-ligatures:no-common-ligatures;" class="">(gen, </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">false</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">);</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">else</b></span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">return</b></span><span style="font-variant-ligatures:no-common-ligatures;" class=""> </span><span class="colour" style="color:rgb(52, 56, 147)">yajl_gen_integer</span><span style="font-variant-ligatures:no-common-ligatures;" class="">(gen, </span><span class="colour" style="color:rgb(0, 84, 147)"><b class="">self</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">.</span><span class="colour" style="color:rgb(112, 61, 170)"><b class="">longLongValue</b></span><span style="font-variant-ligatures:no-common-ligatures;" class="">);</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:12px;line-height:normal;font-family:Consolas;" class=""><span style="font-variant-ligatures:no-common-ligatures;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span><br class=""></div>
</div>
<div class="">&nbsp;</div>
<blockquote type="cite" class=""><div class=""><div style="font-family:Alegreya-Regular;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" class="">I haven’t seen how much of this is implemented in corelibs-foundation yet.&nbsp;<br class=""></div>
</div>
</blockquote></div>
<div class="">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.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">—Jens<br class=""></div>
</div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><div class="">&nbsp;</div>
</div>

</div></blockquote></div><br class=""></body></html>