<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="">In the fix for [SR-381] (links at end) we implement an API for looking up classes by name by searching the protocol conformance table. The initial consumer of this is NSClassFromString() as used by NSKeyedUnarchiver in Foundation.<div class=""><br class=""></div><div class="">The limitation of this approach is that only classes that explicitly conform to protocols can be resolved. We’ll work around this in Foundation by having subclasses that otherwise inherit their protocol conformance explicitly conform to a dummy protocol. However, this behaviour is confusing and would be nice to fix.</div><div class=""><br class=""></div><div class="">One approach I’ve been playing with is for classes always to have an explicit conformance to AnyObject (at least, if they don’t explicitly conform to anything else). (I have a bit of a hacky patch to implement this but it’s failing at link time as there’s no symbol for “_TMps9AnyObject”.)</div><div class=""><br class=""></div><div class="">Before I proceed further down this path – is this an approach worth pursuing or would it be better not to abuse the conformance table for name lookups long term?</div><div class=""><br class=""></div><div class=""><div class="">— Luke</div><div class=""><br class=""></div><div class=""><a href="https://bugs.swift.org/browse/SR-381" class="">https://bugs.swift.org/browse/SR-381</a></div><div class=""><a href="https://github.com/apple/swift/pull/834/files" class="">https://github.com/apple/swift/pull/834/files</a></div><div class=""><br class=""><div apple-content-edited="true" class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="orphans: 2; text-align: -webkit-auto; text-indent: 0px; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="orphans: 2; text-align: -webkit-auto; text-indent: 0px; widows: 2; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; orphans: 2; text-indent: 0px; widows: 2; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: 'Akzidenz-Grotesk BQ'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="">--</div><div class=""><font face="Akzidenz-Grotesk BQ" size="3" class=""><a href="http://www.lukehoward.com" class="">www.lukehoward.com</a><br class="">soundcloud.com/lukehoward</font></div></div></span></div></span></div></div></div></div></div></div></body></html>