Swift: How to disable integer overflow / underflow traps for a function
<p>I'm importing some old C code into a swift project, and porting it across to pure swift code.</p>

<p>Some of it does "encryption" wherein it does something like</p>

<pre><code>let a = UInt8(x) // e.g. 30
let b = a - 237
</code></pre>

<p>In C this just underflows and wraps around, which is fine for this particular function.</p>

<p>In swift this triggers a fatalError and terminates my program with EXC_BAD_INSTRUCTION because swift by default is designed to catch integer over/underflow.</p>

<p>I'm aware I can turn this checking off at the entire project level by compiling with -Ofast, but I'd really like to just turn off the overflow checking for this one line of code (or perhaps just the specific function itself).</p>

<p>Note: I specifically want to preserve the behaviour of the C function, not just promote things up to Int32 or Int64</p>

<p>This particular term seems really hard to google for.</p>

<hr>

<p>Update: The answer is the <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID37" rel="noreferrer">Overflow operators</a>, which are</p>

<ul>
<li><code>&amp;-</code> for subtraction</li>
<li><code>&amp;+</code> for addition</li>
<li><code>&amp;*</code> for multiply</li>
</ul>

<p>I couldn't find them in my previous searching. Oops</p>