<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="">Let’s get a bug into JIRA, then we’ll figure out what we should do here.<div class=""><br class=""></div><div class="">- Tony</div><div class=""><br class=""><div class=""><div><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:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><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:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: 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. </div></div></blockquote><div class=""><br class=""></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.</div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div><div class="">Here’s a snippet of Obj-C code I use for this in my JSON encoder:</div><div class=""><br class=""></div><div class=""><div style="margin: 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 style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">char</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> ctype = </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">self</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class=""><b class="">objCType</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">];</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">switch</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> (ctype) {</span></div><div style="margin: 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><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">case</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #797979" class="">'c'</span><span style="font-variant-ligatures: no-common-ligatures" class="">: {</span></div><div style="margin: 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="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </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></div><div style="margin: 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="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class=""><i class="">// compare it against the singleton kCFBoolean objects:</i></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">if</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">self</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> == (</span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">id</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class=""><b class="">kCFBooleanTrue</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">return</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #343893" class="">yajl_gen_bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">(gen, </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">true</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">);</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">else</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">if</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> (</span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">self</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> == (</span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">id</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class=""><b class="">kCFBooleanFalse</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">return</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #343893" class="">yajl_gen_bool</span><span style="font-variant-ligatures: no-common-ligatures" class="">(gen, </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">false</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">);</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">else</b></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">return</b></span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #343893" class="">yajl_gen_integer</span><span style="font-variant-ligatures: no-common-ligatures" class="">(gen, </span><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class=""><b class="">self</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class=""><b class="">longLongValue</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">);</span></div><div style="margin: 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></div></div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: 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;</div></div></blockquote><br class=""></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.</div><div class=""><br class=""></div><div class="">—Jens</div></div></div></blockquote></div><br class=""></div></div></body></html>