<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2018, at 17:34, Michael Ilseman &lt;<a href="mailto:milseman@apple.com" class="">milseman@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2018, at 4:20 PM, Ben Cohen &lt;<a href="mailto:ben_cohen@apple.com" class="">ben_cohen@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2018, at 12:32 PM, Michael Ilseman via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">For a more general solution, I think a `var numericValue: Int? { get }` on Character would make sense. Unicode defines (at least one) semantics for this and ICU provides this functionality already.</div><br class="Apple-interchange-newline"></div></blockquote></div><br class=""><div class=""><div class="">Minor style point – this should be a failable init on Int rather than a computed property on Character</div><div class=""><br class=""></div><div class="">i.e. Int.init?(_: Character), matching Int.init?(_: String, radix: Int = 10), only it doesn’t need the radix arg cos it’s only a single character.</div><div class=""><br class=""></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">`Int.init?` is probably better, yes. If you wanted to take that to its logical conclusion, that would include `Double.init?` for mathematical constants and some `Rational.init` for fraction graphemes. These are pretty far off the deep end ;-)</div><div class=""><br class=""></div><div class="">Minor logic point – radix isn't important, but that's not because it’s only a single character but rather because of how Unicode(/ICU) defines character properties. Numbers can be much higher than 9, e.g. 万 is ten-thousand. Even worse is cuneiform, which is sexagesimal (and of course cuneiform is properly encoded in Unicode!). Luckily, Unicode’s numeric values are always presented in base-10, AFAICT.</div><div class=""><br class=""></div></div></div></div></blockquote><div><br class=""></div><div>Seems like two different features got tangled here, both of which are useful…</div><div><br class=""></div><div>On the one hand, Chris’ case of “I’ve got a Character and I want to convert ASCII 0-9a-f hex into an Int and it’s incredibly painful in Swift 4”. This is a pretty common everyday need and calls for a failable initializer on Int, similar to the one that takes a String, that is very fast and only covers those characters. Thinking about it, you probably do want an optional radix argument, because you want to explicitly control whether “a” is nil or 10.</div><div><br class=""></div><div>Separate different feature is exposing Unicode properties of characters, including things like 5️⃣ = 5.0, ½ = 0.5 etc, but where a is nil. This possibly works better as a property like numericValue: Double? than an init on Double.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class="">If implemented inside the std lib, it can still access character’s internals, which is a reasonable thing to do for something so performance-sensitive.</div><div class=""><br class=""></div></div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>