<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="">Thank you for bringing this proposal forward Philippe! &nbsp;I initially wanted to include the failable initializers you include here in SE-0080 but it was deemed out of scope at the time. &nbsp;I’m glad to see you have decided to add them. &nbsp;<div class=""><br class=""></div><div class="">The bridging issue is a big one that has caused me frustration in the past especially in cases where NSNumbers created in tests behaved differently than NSNumbers deserialized from servers. &nbsp;It will be great to have consistent behavior now. &nbsp;Somewhat ironically, assuming the archiving and serialization proposals are accepted the issue will be less frequently encountered than it has been in the past. &nbsp;That said, it’s still very much worth fixing. &nbsp;Thank you!<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 6, 2017, at 12:19 PM, Philippe Hausler via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><h1 id="toc_0" style="-webkit-print-color-adjust: exact; margin: 0px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 28px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">NSNumber bridging and Numeric types</h1><ul style="-webkit-print-color-adjust: exact; margin: 15px 0px; padding-left: 30px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Proposal:&nbsp;<a href="file:///Volumes/Users/phausler/Documents/Public/swift-evolution/proposals/NNNN-nsnumber_bridge.md" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196); margin-top: 0px;" class="">SE-NNNN</a></li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Author(s): Philippe Hausler&nbsp;<a href="mailto:phausler@apple.com" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196); margin-top: 0px;" class="">phausler@apple.com</a></li></ul><h5 id="toc_1" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 14px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Revision history</h5><ul style="-webkit-print-color-adjust: exact; margin: 15px 0px; padding-left: 30px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><li style="-webkit-print-color-adjust: exact; margin: 0px;" class=""><strong style="-webkit-print-color-adjust: exact; margin-top: 0px;" class="">v1</strong>&nbsp;Initial version</li></ul><h2 id="toc_2" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Introduction</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">NSNumber</code>&nbsp;has been a strange duck in the Swift world especially when it has come to bridging and interacting with other protocols. An attempt was made to make a type preserving&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">NSNumber</code>&nbsp;subclass; however that defeated numerous optimizations in Foundation and also caused some rather unfortunate disparity between where and how the NSNumbers were created.</p><h2 id="toc_3" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Motivation</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">Swift should have a consistent experience across all the SDK. No matter if you are using Objective-C in your app/framework in addition to Swift or not the behavior should be easily understood and consistent. Furthermore, performance optimizations like tagged pointers or other fast-path accessors in Objective-C or CoreFoundation based code should just work no matter the context in which a&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">NSNumber</code>&nbsp;is created.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">There are some really spooky behaviors as of current; here are a few extreme examples -</p><h4 id="toc_4" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Example 1</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">max</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">if</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">is</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// this is true as of the current build of Swift!</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h4 id="toc_5" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Example 2</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">max</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">if</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">is</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// this is true as of the current build of Swift!</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">else</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">if</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">is</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// Ideally we should get to here</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h4 id="toc_6" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Example 3</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">Int64</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">42</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">if</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> value <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt8</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// This makes sense if NSNumber is viewed as an abstract numeric box</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">But there are some subtile failures that occur as well -</p><h4 id="toc_7" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Example 4</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// Serialization behind the scenes causes numeric failures if we were 100% strict</span>
open <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">class</span> <span class="token class-name" style="-webkit-print-color-adjust: exact;">MyDocument</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSDocument</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">var</span> myStateValue<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span> <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">0</span>
    
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">public</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">static</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">restoreWindow</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>withIdentifier identifier<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">String</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">,</span> state<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSCoder</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">,</span> completionHandler<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> @escaping <span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSWindow</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Error</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Swift</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Void</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
        myStateValue <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> state<span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">decodeObject</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>forKey<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token string" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">"myStateValue"</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">!</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span> <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// this is expected to pass since we encoded a Int16 value and we expect at least to get an Int16 out.</span>
    <span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>
    
    open <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">encodeRestorableState</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>with coder<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSCoder</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
        coder<span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">encodeObject</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>myStateValue<span class="token punctuation" style="-webkit-print-color-adjust: exact;">,</span> forKey<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token string" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">"myStateValue"</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h4 id="toc_8" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Example 5</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// lets say you have a remote server you have no control over except getting JSON requests back</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// the format specifies that the response will have a timestamp in a value that is the integral number of milliseconds since 1970</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// e.g. { "timestamp" : 1487980252519 } is valid JSON, but a recent server upgrade changes it to be  "timestamp" : 1487980252519.0 } which is also valid JSON</span>

<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// initially code could be written validly as</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> payload <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">JSONSerialization</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">jsonObject</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>with<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> response<span class="token punctuation" style="-webkit-print-color-adjust: exact;">,</span> options<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">[</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">]</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">[</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">String</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">]</span>

<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// but a remote server change could break things if we were strict and requires this code change</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> payload <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">JSONSerialization</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">jsonObject</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>with<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> response<span class="token punctuation" style="-webkit-print-color-adjust: exact;">,</span> options<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">[</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">]</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">[</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">String</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Double</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">]</span>

<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// But the responses are still integral!</span>
<span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h4 id="toc_9" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Example 6</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> itDoesntDoWhatYouThinkItDoes <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">Int8</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">max</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span> <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// counterintutively (as legacy baggage of C) this is Int8(-1)</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">All of these examples boil down to the simple question: what does&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">as?</code>&nbsp;mean for NSNumber. It is worth noting that&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">is</code>&nbsp;should follow the same logic as&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">as?</code>.</p><h2 id="toc_10" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Proposed solution</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">as?</code>&nbsp;for NSNumber should mean&nbsp;<q style="-webkit-print-color-adjust: exact;" class="">Can I safely express the value stored in this opaque box called a NSNumber as the value I want?</q>.</p><h4 id="toc_11" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Solution Example 1</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// The trivial case of "what you put in the box is what you get out"</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">UInt32</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">543</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> v <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt32</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// v is UInt32(543)</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h4 id="toc_12" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Solution Example 2</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// The trivial case of the other way around from Solution Example 1</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> v<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt32</span> <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">543</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> v <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// n == NSNumber(value: 543)</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h4 id="toc_13" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Solution Example 3</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// Safe "casting"</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">UInt32</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">543</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> v <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// v is Int16(543)</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">In this case&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">n</code>&nbsp;is storing a value of 543 obtained from a&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">UInt32</code>. Asking the question&nbsp;<q style="-webkit-print-color-adjust: exact;" class="">Can I safely express the value stored in this opaque box called a&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">NSNumber</code>&nbsp;as the value I want?</q>; we have 543, can it be expressed safely as a&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Int16</code>? Absolutely!</p><h4 id="toc_14" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Solution Example 4</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// Failures when casting that losses the value stored</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> n <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">UInt32</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">543</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> v <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> n <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">as</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int8</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// v is nil</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">In this case&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">n</code>&nbsp;is storing a value of 543 obtained from a&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">UInt32</code>&nbsp;but when asked can it be safely represented as the requested type&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Int8</code>&nbsp;the answer is; of course not.</p><h4 id="toc_15" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Solution Example 5</h4><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">let</span> v <span class="token operator" style="-webkit-print-color-adjust: exact;">=</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">Int8</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(230, 219, 116);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>value<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">max</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: slategray;">// v is nil because Int64.max cannot be safely expressed as Int8</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><h2 id="toc_16" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Detailed design</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The following methods will be changed deprecated in swift 4 because the behavior is truncating not an assertion of exactly:</p><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int8</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt8</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt16</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int32</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt32</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt64</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Float</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Double</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">CGFloat</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Bool</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(174, 129, 255);">_</span> number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span><span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">To the optional variants as such:</p><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><div class="prism-show-language" style="-webkit-print-color-adjust: exact; position: relative;"><div class="prism-show-language-label" style="-webkit-print-color-adjust: exact; background-color: rgb(207, 207, 207); display: inline-block; position: absolute; bottom: auto; left: auto; top: 0px; right: 0px; width: auto; height: auto; font-size: 0.9em; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 5px; padding: 0px 0.5em; text-shadow: none; z-index: 1; -webkit-box-shadow: none; box-shadow: none; transform: none;">Swift</div></div><pre class="line-numbers language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(39, 40, 34); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; white-space: pre-wrap; overflow: auto; padding: 1em 1em 1em 3.8em; border-top-left-radius: 0.3em; border-top-right-radius: 0.3em; border-bottom-right-radius: 0.3em; border-bottom-left-radius: 0.3em; color: rgb(248, 248, 242); text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none; position: relative; counter-reset: linenumber 0;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: rgba(0, 0, 0, 0.298039) 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none; position: relative;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int8</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt8</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int16</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt16</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int32</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt32</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int64</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt64</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Float</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Double</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">CGFloat</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Bool</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">Int</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">UInt</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact;">{</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token operator" style="-webkit-print-color-adjust: exact;">?</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>exactly number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(102, 217, 239);">init</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">(</span>truncating number<span class="token punctuation" style="-webkit-print-color-adjust: exact;">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(166, 226, 46);">NSNumber</span><span class="token punctuation" style="-webkit-print-color-adjust: exact;">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact;">}</span>
<span class="line-numbers-rows" style="-webkit-print-color-adjust: exact; position: absolute; pointer-events: none; top: 0px; left: -3.8em; width: 3em; letter-spacing: -1px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(153, 153, 153); -webkit-user-select: none;"><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span><span style="-webkit-print-color-adjust: exact; pointer-events: none; display: block; counter-increment: linenumber 1;" class=""></span></span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The behavior of exactly will be an exact bitwise representation for stored integer types such that any initialization must be able to express the initialized type with the stored representation in the NSNumber or it will fail and return nil. The truncating versions on the other hand will be similar to fetching the value via that type accessor. e.g.&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Int8(truncating: myNSNumber)</code>&nbsp;will be tantamount to calling&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">int8Value</code>on said number</p><h2 id="toc_17" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Impact on existing code</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The one big repercussion is that the bridging methods cannot be versioned for swift 3 and swift 4 availability so we must pick one implementation or another for the bridging. Swift 4 modules or frameworks must bridge in the same manner as Swift 3 since the implementation is the behavioral difference, not the calling module.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">There are a number of places in frameworks where NSNumbers are used to provide results. For example CoreData queries can potentially yield NSNumbers, Coding and Archival use NSNumbers for storage under the hood, Serialization uses NSNumbers for numeric representations (there are many more that apply these are just a few that can easily lead to corruption or malformed data when users accidentally truncate via the current bridging behavior).&nbsp;</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">Overall I am of the belief that any case that this would break existing code it was potentially incorrect behavior on the part of the developer using the bridge of NSNumber and if it is not the facilities of NSNumber are still present (you can still call&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">NSNumber(value: Int64.max).int8Value</code>&nbsp;to get&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">-1</code>&nbsp;if that is what you really mean. That way is unambiguous and distinctly clear for maintainable code and reduces the overall magic/spooky behavior.</p><h2 id="toc_18" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Source compatibility</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">This does change the result of cast via&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">as?</code>&nbsp;so it does not change source compatability but it does change runtime compatability. In the end, round tripped NSNumbers into collections that bridge across are relatively rare and it is much more common to get NSNumbers out of APIs. The original&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">as?</code>&nbsp;cast required developers to be aware of potential failure by syntax, the change here is a safer way of expressing values for all numbers in one uniform methodology that is both more performant as well as more correct in more common cases. In short the runtime effect is a step in the right direction.</p><h2 id="toc_19" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Effect on ABI stability</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">This change should have no direct impact upon ABI.</p><h2 id="toc_20" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Effect on API resilience</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The initializers that had no decoration are marked as deprecated so the remaining portion is considered additive only.</p><h2 id="toc_21" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Considerations for Objective-C platforms</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">This brings in line the concepts of the existing Objective-C APIs to the intent that was originally used for NSNumber and the usage. Bridging NSNumbers (for platforms that support it and cases that are supported) should always respect the concept of tagged pointers. In just property list cases alone it is aproximately a 2% performance loss to avoid the tagged pointer cases; just by using swift there should be little to no performance penalty for sending these types either direction on the bridge in comparison to the equivalent Objective-C implementations.</p><h2 id="toc_22" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Considerations for Linux platforms</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">We do not have bridging on Linux so the&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">as?</code>&nbsp;cast is less important; but if it were to have bridging this would be the desired functionality.</p><h2 id="toc_23" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Alternatives considered</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">We have explored making NSNumbers created in Swift to be strongly type preserving. This unfortunately results in a severe inconsistency between APIs implemented in Swift and those implemented in Objective-C. Instead of having a disparate behavior depending on the spooky action determined in an opaque framework it is better to have a simple story no matter what language the NSNumber was made in and no matter what facility it was created with. To do so we have only one real way of representing numeric types; meet halfway in the middle between erasing all type information and requiring a pedantic matching of type information and always allow a safe expression of the numeric value.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">Using initializers for&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Integer</code>&nbsp;or&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: pre-wrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">FloatingPoint</code>&nbsp;protocol adopters on NSNumber was considered but was determined out of scope for this change and may be considered seperately from the behavior of NSNumber bridging.</p></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>