2

After spending a few hours to integrate swift files successfully to my Objective-C based iOS project, I face the next challenge now :

  1. In one of my Objective-C class header (Say, MyObjCClass.h), I do the forward declaration for MySwiftClass.
  2. In the respective .m file, I define an instance of MySwiftClass _swiftClassInstance.
  3. In the init method of MyObjCClass, I try to instantiate it as follows :

_swiftClassInstance = [[MySwiftClass alloc] init];

When I compile the code, I get 2 errors:

  • Receiver 'MySwiftClass' for class message is a forward declaration
  • Receiver type 'MySwiftClass' for instance message is a forward declaration

I have already done following :

  1. Imported MyProject-Swift.h in the MyObjCClass.m file.
  2. Marked the swift class with @objc and open

So, what can be the reason for the issue?

Harish J
  • 525
  • 1
  • 4
  • 16
  • What is your Swift class actually called? You may need to give it an Objective-C visible/suitable name using `@objc(MySwiftClass)` – Gereon Dec 29 '17 at 08:51

0 Answers0