Receiver ‘Example’ for class message is a forward declaration??

When met with this error in ObjC project while compiling, it means:

Example class is declared by @class in its invoker's class header but not directly #import.

We have 2 ways to solve this problem:

  • Directly declare Example class by #import “Example.h” in the header.
  • Add a method to return specific Example you want in invoker’s class header. (use this way if you use both ObjC and Swift and Example is a Swift class in a framework project.)

How to import Swift code into Objective-C Module or Framework?

  • Import Swift files into the module you want.
  • Modify all swift declarations of classes, properties or methods you want to use in your module with @objc public in front of each declaration. Whereas classes don’t need @objc, just put public in front of it would be OK.
  • And for the left, do as what apple said here.

OK, there you go now 🙂