title: Using an implementation of a Swift protocol within Obj-C
body: <p>I'm trying to implement a mediator sort of pattern with a mixture of Swift and Obj-C. The issue I'm facing is with how to deal with using the Swift protocol implementation classes from Obj-C.  Check out the code to see what I mean:</p>
  
  <p>The Swift protocol and implementation of it:</p>
  
  <pre><code>@objc public protocol TheProtocol {
      func someMethod()
  }
  
  @objc public class SwiftClass: NSObject, TheProtocol {
      public func someMethod() {
          print("someMethod Swift")
      }
  }
  </code></pre>
  
  <p>The ObjC-implementation of the protocol:</p>
  
  <pre><code>#import "SwiftAndObjC-Swift.h"
  @interface ObjCClass : NSObject &lt;TheProtocol&gt;
  - (void) someMethod;
  @end
  
  
  @implementation ObjCClass
  - (void) someMethod
  {
      NSLog(@"someMethod ObjC");
  }
  @end
  </code></pre>
  
  <p>My question is how is it possible to define some type in ObjC which is capable of referencing either a SwiftClass or an ObjCClass. For example this does not compile:</p>
  
  <pre><code>#import "SwiftAndObjC-Swift.h"
  ...
  TheProtocol *p = [[ObjCClass alloc] init];
  // Error: "Use of undeclared identifier TheProtocol"
  </code></pre>
  
  <p>This will compile:</p>
  
  <pre><code>@class TheProtocol
  TheProtocol *p = [[ObjCClass alloc] init];
  </code></pre>
  
  <p>But not p can't be used:</p>
  
  <pre><code>@class TheProtocol
  TheProtocol *p = [[ObjCClass alloc] init];
  [p someMethod];
  // Error: Receiver type "The Protocol" is a forward declaration"
  </code></pre>
  
  <p>(Adding casts to the assignment and/or method invocation doesn't help)</p>
  
  <p>Any solutions?</p>