<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=""><div class="">A developer using the framework I work on <a href="https://forums.couchbase.com/t/exception-caught-in-map-block-of-view-invalid-type-in-json-write--swiftvalue/10808" class="">just reported</a> an exception which is triggered by NSJSONSerialization (see backtrace below.) Basically an NSDictionary gets parsed from JSON data (in Obj-C), passed to a Swift function, which then calls another function (written in Obj-C) that serializes it back to JSON data. That last step is crashing due to some problem with bridging.</div><div class=""><br class=""></div><div class="">The events leading up to this are:</div><div class=""><br class=""></div><div class="">1. The framework (written in Obj-C) parses some JSON data using NSJSONSerialization, resulting in an NSDictionary.</div><div class="">2. The NSDictionary is passed as a parameter to a block; the parameter is typed as `NSDictionary*`.</div><div class="">3. The block is part of the application, which is written in Swift.</div><div class="">4. The block in turn passes that NSDictionary to a function in the framework (through a parameter is typed as `id`)</div><div class="">5. The framework uses NSJSONSerialization to convert that id to data.</div><div class=""><br class=""></div><div class="">Step 5 is triggering an assertion failure in Foundation. Apparently it failed to un-bridge a Swift value in an array back into an NSObject. (From the contents of the dictionary I know that the single-object array in question contains a string.)</div><div class=""><br class=""></div><div class="">Any idea what’s going on here? I’ve never seen this happen before, and this part of our framework has been around for 2 ½ years. People have successfully built Swift apps using the framework. (This app was built with Xcode 8.0; don’t know what the OS is, though.)</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Invalid type in JSON write (_SwiftValue)<div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>3 Foundation 0x0000000111263284 _writeJSONValue + 668</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>4 Foundation 0x00000001112636d9 ___writeJSONArray_block_invoke + 132</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>5 CoreFoundation 0x0000000118e1ce2a -[__NSSingleObjectArrayI enumerateObjectsWithOptions:usingBlock:] + 58</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>6 Foundation 0x00000001112633df _writeJSONArray + 330</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>7 Foundation 0x0000000111263204 _writeJSONValue + 540</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>8 Foundation 0x0000000111262f94 -[_NSJSONWriter dataWithRootObject:options:error:] + 124</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>9 Foundation 0x0000000111262e74 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333</div><span class="Apple-tab-span" style="white-space: pre;">        </span>...<br class="Apple-interchange-newline"><br class=""></div><div class="">—Jens</div></body></html>