<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="">Hello,<div class=""><br class=""></div><div class="">I’m having an issue migrating some old Objective-C code that looks like this:</div><div class=""><br class=""></div><div class="">@implementation Foo</div><div class=""><br class=""></div><div class="">- (void)load {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// Swizzle one of Bar’s methods to call Foo’s baz method</div><div class="">}</div><div class=""><br class=""></div><div class="">- (void)baz {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>[self baz];</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if ([self isKindOfClass:NSClassFromString(@“Bar”)]) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>Bar *bar = (Bar *)self; // I can’t migrate this</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>// work with bar</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class="">}</div><div class=""><br class=""></div><div class="">@end</div><div class=""><br class=""></div><div class="">I’m trying to cast self to a Bar at runtime, and use it to call Bar’s methods. Sounds like an easy to task for unsafeBitCast, right? The issue is that I don’t have access to the implementation of Bar’s class at compile time (this is a plugin, so it’s loaded by another application which contains Bar). In Objective-C I can create a header and stick a dummy interface for Bar in it; the cast will work if Bar exists at runtime. However, in Swift, unsafeBitCast requires me to use Bar.self, which does not exist. Is there any way to get this cast to work?</div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><div 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="">Saagar Jha</div>

</div>
<br class=""></div></body></html>