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