<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>My plan was just to map any flat unmangled names to SwiftFoundation classes without the boilerplate explicit mappings, but happy to change approaches.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">That's what the code in the branch I posted yesterday does, but I need to fix it to encode the mangled name for non-one level class types - was planning to implement NSClassFromString/NSStringFromClass at the same time so at least the logic is in one place, and those can be refined over time.<br><br>Sent from my iPhone</div><div><br>On 24 Dec 2015, at 11:07, Philippe Hausler &lt;<a href="mailto:phausler@apple.com">phausler@apple.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">So one thing we can do in the interim until there is a sanctioned way for us to convert strings to classes and classes to strings is we can register the classes globally for transformation so that the Foundation or SwiftFoundation module name won’t be an issue.</div><div class=""><br class=""></div><div class="">By doing this early on in the initialization for NSKeyedArchiver, once of course.</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; NSKeyedArchiver.setClassName("NSArray", forClass:&nbsp;NSArray.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSByteCountFormatter", forClass:&nbsp;NSByteCountFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSData", forClass:&nbsp;NSData.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSDate", forClass:&nbsp;NSDate.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSDateFormatter", forClass:&nbsp;NSDateFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSDateIntervalFormatter", forClass:&nbsp;NSDateIntervalFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSDecimalNumber", forClass:&nbsp;NSDecimalNumber.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSDictionary", forClass:&nbsp;NSDictionary.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSEnergyFormatter", forClass:&nbsp;NSEnergyFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSFormatter", forClass:&nbsp;NSFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSLengthFormatter", forClass:&nbsp;NSLengthFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMassFormatter", forClass:&nbsp;NSMassFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMessagePort", forClass:&nbsp;NSMessagePort.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMutableArray", forClass:&nbsp;NSMutableArray.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMutableData", forClass:&nbsp;NSMutableData.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMutableDictionary", forClass:&nbsp;NSMutableDictionary.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMutableSet", forClass:&nbsp;NSMutableSet.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSMutableString", forClass:&nbsp;NSMutableString.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSNotification", forClass:&nbsp;NSNotification.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSNumber", forClass:&nbsp;NSNumber.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSNumberFormatter", forClass:&nbsp;NSNumberFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSPersonNameComponentsFormatter", forClass:&nbsp;NSPersonNameComponentsFormatter.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSPort", forClass:&nbsp;NSPort.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSRegularExpression", forClass:&nbsp;NSRegularExpression.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSSet", forClass:&nbsp;NSSet.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSSocketPort", forClass:&nbsp;NSSocketPort.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSString", forClass:&nbsp;NSString.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSTextCheckingResult", forClass:&nbsp;NSTextCheckingResult.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSTimeZone", forClass:&nbsp;NSTimeZone.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSUUID", forClass:&nbsp;NSUUID.self)<br class="">&nbsp; &nbsp;&nbsp;NSKeyedArchiver.setClassName("NSValue", forClass:&nbsp;NSValue.self)</div><div class=""><br class=""></div><div class="">I have a few more things that I was looking at for supporting this that might be useful depending on how far along you are.</div><div class=""><br class=""></div><div class="">This should give us at least a head start on the NSCoding compliant Foundation classes and user classes can come next once we have support.</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 23, 2015, at 3:33 PM, Luke Howard &lt;<a href="mailto:lukeh@padl.com" class="">lukeh@padl.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On 24 Dec 2015, at 10:12 AM, Philippe Hausler &lt;<a href="mailto:phausler@apple.com" class="">phausler@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Georgia; font-size: 18px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; 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;">NSCoding will have to use something to transform from strings to classes, and that satisfy the two cases (or more) that we have already shown, currently there is no thing that does that in either form; either mangled or non mangled. Basically we need something to implement NSClassFromString with. Which we have clearly shown that dlsym does not fully meet the needs since there are cases that will emit as “module.classname” and others that emit as the mangled name. The simple case is probably going to be the a very common usage pattern for consumers (and of previously built applications). The inner class should definitely be handled in addition to this case.</div></div></blockquote><div class=""><br class=""></div><div class="">* If the mangled name is present in the archive, you can re-mangle it to get the metadata accessor</div><div class="">* If it’s a one-level unmangled name representing a class, it can be mangled</div><div class="">* If it’s a zero-level unmangled name, then it seems reasonable for a first implementation to assume it’s a SwiftFoundation class (or that the caller has set an explicit mapping)</div><div class=""><br class=""></div><div class="">Noted that dlsym() will only work with public symbols.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Georgia; font-size: 18px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; 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;">Are there any methods that can fetch the name (either the symbolic or the readable) given a AnyClass in the runtime to get work started here? I think it is definitely sensible as a start to restrict this just to descendants of the class NSObject. I would presume that since the Metadata is potentially volatile contents we should use something along the lines of&nbsp;swift_getTypeName etc?</div></div></blockquote></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;"><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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; float: none; display: inline !important;" class="">I have been using _typeName() but it always demangles – for interop with existing archives we need to match the behaviour of libobjc's class_getName() (equivalent to NSStringFromClass), which appears to demangle one-level classes.</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; 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;">— Luke</div></div></blockquote></div><br class=""></div></blockquote></body></html>