<div dir="ltr">Hi Brian!<div><br></div><div>Thanks for the replies. I haven’t been able to hack on this for a few days but hopefully I can over the holiday break this weekend.</div><div><br></div><div>I’ve been experimenting with building XCTest for watchOS and constructing a test harness. I’ve gotten it to the point where I can execute the same test class in iOS and watchOS, with the caveat that I need to enumerate the test methods like so:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">import</span><span style="font-variant-ligatures:no-common-ligatures"> XCTest</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">class</span><span style="font-variant-ligatures:no-common-ligatures"> ClaspTests: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">XCTestCase</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">static</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> allTests = {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">return</span><span style="font-variant-ligatures:no-common-ligatures"> [</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">            (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(180,38,26)">&quot;testPassingTest&quot;</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">testPassingTest</span><span style="font-variant-ligatures:no-common-ligatures">),</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">            ]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> testPassingTest() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(180,38,26)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">print</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures">&quot;This is my test method.&quot;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,149,175)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">        </span><span style="font-variant-ligatures:no-common-ligatures">XCTAssertTrue</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">true</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div><br></div><div>This works fine for Swift tests, but the Swift implementation of XCTestCase doesn&#39;t inherit from NSObject, so I can’t run Objective-C tests in it. I was hoping to make a new Swift class, exposing it to Objective-C as a false XCTestCase using <span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">@objc</span><span style="color:rgb(0,0,0);font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures">(XCTestCase)</span>, and then making a subclass of XCTestCase in Swift to relay its tests back to XCTest.</div><div><br></div><div>My goal here is to get as much drop-in support for running existing test suites in watchOS as possible. I can get there reasonably well with what I have so far—just by adding the <span style="color:rgb(0,0,0);font-family:menlo;font-size:11px">allTests </span>property—but it would be awesome to enumerate Objective-C classes as well.</div><div><br></div><div>Being able to enumerate the test methods of the Swift classes would be a feather in the cap of this experiment, and would probably be beneficial to XCTest as a whole, but I’m not sure how I would go about that in a non-Objective-C-runtime world.</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="font-family:Helvetica"><br></div><div style="font-family:Helvetica">Jeff Kelley</div><div style="font-family:Helvetica"><br></div><div style="font-family:Helvetica"><a href="mailto:SlaunchaMan@gmail.com" style="color:rgb(17,85,204)" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" style="color:rgb(17,85,204)" target="_blank">@SlaunchaMan</a> | <a href="http://jeffkelley.org/" style="color:rgb(17,85,204)" target="_blank">jeffkelley.org</a></div></div></div></div>
<br><div class="gmail_quote">On Mon, Nov 21, 2016 at 11:06 AM, Brian Gesiak <span dir="ltr">&lt;<a href="mailto:modocache@gmail.com" target="_blank">modocache@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I&#39;m curious: what are you hoping to accomplish with corelibs-xctest? If we can help you by modifying corelibs-xctest itself, that could be another option here. :)<span class="HOEnZb"><font color="#888888"><div><br></div><div>- Brian Gesiak</div><div><br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 21, 2016 at 10:46 AM, Jeff Kelley via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>The type comes from XCTest. I’m trying to enumerate Objective-C methods in order to use them with XCTest in the open-source Swift version of XCTest, which needs the tests to be supplied as this type:</div><div><br></div><div><pre style="word-wrap:break-word;white-space:pre-wrap">/// This is a compound type used by `XCTMain` to represent tests to run. It combines an
/// `XCTestCase` subclass type with the list of test case methods to invoke on the class.
/// This type is intended to be produced by the `testCase` helper function.
/// - seealso: `testCase`
/// - seealso: `XCTMain`
public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, (XCTestCase) throws -&gt; Void)])</pre><div><br></div></div><span><div><br></div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span class="m_2840212140094280891m_-9056592914848156713Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;line-height:normal;border-spacing:0px"><div style="word-wrap:break-word"><div>Jeff Kelley</div><div><br></div><div><a href="mailto:SlaunchaMan@gmail.com" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" target="_blank">@Slaun<wbr>chaMan</a> | <a href="http://jeffkelley.org" target="_blank">jeffkelley.org</a></div></div></span></div></div></div></div></div>
</div>
<br></span><div><div class="m_2840212140094280891h5"><div><blockquote type="cite"><div>On Nov 21, 2016, at 1:13 AM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt; wrote:</div><br class="m_2840212140094280891m_-9056592914848156713Apple-interchange-newline"><div><div dir="ltr">&quot;throws&quot; is the part that&#39;s not representable in Obj-C. Why are you using it? If you&#39;re interacting with method_getImplementation, you need to think like the Obj-C runtime.<div><br></div><div><a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtHowMessagingWorks.html#//apple_ref/doc/uid/TP40008048-CH104-SW1" target="_blank">https://developer.apple.com/li<wbr>brary/content/documentation/Co<wbr>coa/Conceptual/ObjCRuntimeGuid<wbr>e/Articles/ocrtHowMessagingWor<wbr>ks.html#//apple_ref/doc/uid/<wbr>TP40008048-CH104-SW1</a><br><div><br></div><div>This works:</div><div><br></div><div>    typealias DescriptionMethod = @convention(c) (NSObject, Selector) -&gt; NSString </div><div><br></div><div>    let fn = unsafeBitCast(method_getImplem<wbr>entation(class_getInstanceMeth<wbr>od(NSObject.self, &quot;description&quot;)), DescriptionMethod.self)</div><div><br></div><div>    fn(NSObject(), &quot;description&quot;) as String</div><div><br></div><div><div class="gmail_extra"><br clear="all"><div><div class="m_2840212140094280891m_-9056592914848156713gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Sun, Nov 20, 2016 at 9:41 PM, Jeff Kelley <span dir="ltr">&lt;<a href="mailto:slaunchaman@gmail.com" target="_blank">slaunchaman@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Still trying on this (copied the code directly, Foo is actually XCTestCase):<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(4,51,255)"><span style="font-variant-ligatures:no-common-ligatures">typealias</span><span style="font-variant-ligatures:no-common-ligatures"> TestMethod = </span><span style="font-variant-ligatures:no-common-ligatures">@convention</span><span style="font-variant-ligatures:no-common-ligatures">(c) (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">XCTestCase</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures">throws</span><span style="font-variant-ligatures:no-common-ligatures"> -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Void</span></div></div><div><br></div><div>This seagulls the compiler with “<span style="font-family:menlo;font-size:11px">error: &#39;(XCTestCase) throws -&gt; Void&#39; is not representable in Objective-C, so it cannot be used with &#39;@convention(c)</span><font face="Menlo"><span style="font-size:11px">’</span></font>”. I’m trying to use it here:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> testMethod: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">IMP</span><span style="font-variant-ligatures:no-common-ligatures"> = method_getImplementation(metho<wbr>d)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">let</span><span style="font-variant-ligatures:no-common-ligatures"> test: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">TestMethod</span><span style="font-variant-ligatures:no-common-ligatures"> = unsafeBitCast(testMethod,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">                                     to: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">TestMethod</span><span style="font-variant-ligatures:no-common-ligatures">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">self</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">testMethods.append((methodName </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">as</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">String</span><span style="font-variant-ligatures:no-common-ligatures">, test))</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div>If I try to put the type directly in the call to unsafeBitCast(), the compiler gives me an error:</div><div><br></div><div><div style="margin:0px 0px 0px 12px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px">Attribute can only be applied to types, not declarations<b></b></div><div style="margin:0px 0px 0px 12px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><br></div></div><div>Thanks for your suggestions! I hadn’t seen @convention() before.</div><div><br></div><div><span class="m_2840212140094280891m_-9056592914848156713gmail-"><br><div>
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-numeric:normal;line-height:normal"><div style="word-wrap:break-word"><div>Jeff Kelley</div><div><br></div><div><a href="mailto:SlaunchaMan@gmail.com" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" target="_blank">@Slaun<wbr>chaMan</a> | <a href="http://jeffkelley.org/" target="_blank">jeffkelley.org</a></div></div></span></div></div></div></div></div>
</div>
<br></span><div><div class="m_2840212140094280891m_-9056592914848156713gmail-h5"><div><blockquote type="cite"><div>On Nov 21, 2016, at 12:08 AM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt; wrote:</div><br class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134Apple-interchange-newline"><div><div dir="ltr">For a function such as bar() above, the type you want to cast the IMP to would probably be &quot;@convention(c) (Foo, Selector) -&gt; ()&quot;.<div class="gmail_extra">
<br><div class="gmail_quote">On Sun, Nov 20, 2016 at 9:05 PM, Jeff Kelley <span dir="ltr">&lt;<a href="mailto:slaunchaman@gmail.com" target="_blank">slaunchaman@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Thanks Jacob! I tried using unsafeBitCast, but it fails with the following: “fatal error: can&#39;t unsafeBitCast between types of different sizes”. I considered wrapping every call in a closure that calls objc_msgSend(), but alas, that’s not exposed to Swift. I have another approach in mind, so I’ll try that next.<div><br></div><div><span><br><div>
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557Apple-style-span" style="border-collapse:separate;font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word"><div>Jeff Kelley</div><div><br></div><div><a href="mailto:SlaunchaMan@gmail.com" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" target="_blank">@Slaun<wbr>chaMan</a> | <a href="http://jeffkelley.org/" target="_blank">jeffkelley.org</a></div></div></span></div></div></div></div></div>
</div>
<br></span><div><div class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134h5"><div><blockquote type="cite"><div>On Nov 19, 2016, at 1:58 AM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt; wrote:</div><br class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557Apple-interchange-newline"><div><div dir="ltr">I imagine unsafeBitCast would be the way to go here. But are you assuming that all of the instance methods have type &quot;(Foo) throws -&gt; Void&quot; ? Or do you somehow want to dynamically use the type information?<div class="gmail_extra"><br clear="all"><div><div class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Fri, Nov 18, 2016 at 10:37 PM, Jeff Kelley via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word">Hello,<div><br></div><div><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933Apple-tab-span" style="white-space:pre-wrap">        </span>I’m trying to enumerate the methods of a class in Swift using the Objective-C runtime. Everything is working fine so far, except for the very last step. Suppose I have a Swift class like this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">class</span><span style="font-variant-ligatures:no-common-ligatures"> Foo</span><span style="font-variant-ligatures:no-common-ligatures">: </span><span style="color:rgb(52,149,175);font-variant-ligatures:no-common-ligatures">SomeSuperclass</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">@objc</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">func</span><span style="font-variant-ligatures:no-common-ligatures"> bar() {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(180,38,26)"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures">&quot;Hello, World!&quot;</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures">    </span><br class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933webkit-block-placeholder"></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><br></div><div><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933Apple-tab-span" style="white-space:pre-wrap">        </span>Using the Objective-C runtime methods, I can get the method with <span style="color:rgb(52,149,175);font-family:menlo;font-size:11px">class_copyMethodList</span> and then get to the method’s implementation using <span style="color:rgb(52,149,175);font-family:menlo;font-size:11px">method_getImplementation</span><wbr>. However, what I need to do next is to stick this into a tuple that looks like this:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">typealias</span><span style="font-variant-ligatures:no-common-ligatures"> FooEntry = (fooClass: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">SomeSuperclass</span><span style="font-variant-ligatures:no-common-ligatures">.Type, methods: [(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">String</span><span style="font-variant-ligatures:no-common-ligatures">, (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Foo</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">throws</span><span style="font-variant-ligatures:no-common-ligatures"> -&gt; </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">Void</span><span style="font-variant-ligatures:no-common-ligatures">)])</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933Apple-tab-span" style="white-space:pre-wrap">        </span>For now, the workaround is to make a static variable that returns all of the entries:</div><div><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">static</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">var</span><span style="font-variant-ligatures:no-common-ligatures"> allEntries = {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)">return</span><span style="font-variant-ligatures:no-common-ligatures"> [</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">            (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(180,38,26)">&quot;bar&quot;</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,149,175)">bar</span><span style="font-variant-ligatures:no-common-ligatures">),</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">        ]</span></div><div><span style="font-family:menlo;font-size:11px">    </span><span style="font-family:menlo;font-size:11px">}</span></div><div><br></div><div><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933Apple-tab-span" style="white-space:pre-wrap">        </span>Is there any way to go from the raw <span style="color:rgb(52,149,175);font-family:menlo;font-size:11px">IMP</span> that I get back from the runtime to the Swift type so I can construct this list dynamically?</div><div><br></div><div><br><div>
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="font-family:helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><span class="m_2840212140094280891m_-9056592914848156713gmail-m_9151264134778263134m_-5343275286513492557m_-7480237009779366933Apple-style-span" style="border-collapse:separate;font-variant-ligatures:normal;font-variant-numeric:normal;line-height:normal"><div style="word-wrap:break-word"><div>Jeff Kelley</div><div><br></div><div><a href="mailto:SlaunchaMan@gmail.com" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" target="_blank">@Slaun<wbr>chaMan</a> | <a href="http://jeffkelley.org/" target="_blank">jeffkelley.org</a></div></div></span></div></div></div></div></div>
</div>

<br></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div></div></div>
</div></blockquote></div><br></div></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>