title: iOS runtime: when doing code module isolation, why protocol OK, method list not OK?
body: <p>when doing code module isolation ( a little like subprojects ) ,</p>
  <p>There are one Main Project and two frameworks. Framework A depends on Framework B.</p>
  <p>Main Project has the two framework dependencies, and import Framework A , unimport Framework B.</p>
  <ul>
  <li>Framework A has:</li>
  </ul>
  <pre><code>public protocol AccountLotus {
       func methodA()
  }
  </code></pre>
  <ul>
  <li>Framework B has:</li>
  </ul>
  <pre><code>class AccountLotusoot: NSObject, AccountLotus {
     func methodA(){}
  }
  
  </code></pre>
  <p>in the main project,</p>
  <p>with runtime reflection, string <code>ModeleB.AccountLotusoot</code> to class (NSObject) and comes an instance casted as <code>AccountLotus</code>.</p>
  <p>then the instance call <code>methodA</code>, and it works well.</p>
  <p><code>methodA</code> is implemented in frameworkB, not imported in the main project.</p>
  <p><strong>At the same time:</strong></p>
  <p>the framework A has</p>
  <pre><code>public class Maid: NSObject{}
  </code></pre>
  <p>and the framework B has:</p>
  <pre><code>
  extension Maid{
      dynamic func loginServiceName() -&gt; String{
          return &quot;ModeleB.AccountLotusoot&quot;
      }
  }
  
  </code></pre>
  <p>in the main project, call <code>printMethodNamesForClass(cls: Maid.self)</code>, not OK</p>
  <p>The method defined and implemented in framework B is needed.</p>
  <pre><code>func printMethodNamesForClass(cls: AnyClass) {
      var methodCount: UInt32 = 0
      let methodList = class_copyMethodList(cls, &amp;methodCount)
      if let methodList = methodList{
          let arr = Array(arrayLiteral: methodList)
          for (i, m) in arr.enumerated(){
              let name: String = methodName(m: m.pointee) ?? &quot;Not Known&quot;
              print(&quot;#\(i): \(name)&quot;)
          }
          free(methodList)
      }
  }
  
  
  func methodName(m: Method) -&gt; String? {
      let sel = method_getName(m)
      let nameCString = sel_getName(sel)
      return String(cString: nameCString)
  }
  
  </code></pre>
  <p>The above example and below are both based on runtime, why the second one not OK, and how to solve it.</p>
  <p><a href="https://github.com/BoxDengJZ/ModuleUnImport/tree/main/two" rel="nofollow noreferrer">code in github</a></p>