0

I have problem with generated ObjC header file (Project-Swift.h) from Swift classes.

Header file contains representation of defined Swift classes and all imports of required dependencies. Actually I combine ObjC with Swift in one project together. Everything works fine until I would like create subclass XYZTableViewController of Swift class ABCTableViewController from external framework.

Definition of class from swift file:

@objc class XYZTableViewController: ABCTableViewController { ... }

Generated content from Project-Swift.h:

SWIFT_CLASS("_TtC6Abc22XYZTableViewController") @interface XYZTableViewController : ABCTableViewController - (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER; - (nonnull instancetype)initWithNibName:(NSString * _Nullable)nibNameOrNil bundle:(NSBundle * _Nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER; - (nonnull instancetype)initWithStyle:(UITableViewStyle)style OBJC_DESIGNATED_INITIALIZER; @end

Compilation finish with this error:

Project-Swift.h:140:37: Cannot find interface declaration for 'ABCTableViewController', superclass of 'XYZTableViewController'; did you mean 'UITableViewController'?

It works if I'm importing module into .m files for the external framework and defining properties of related class type.

Does have anybody that problem or another similar complications?

2 Answers2

2

You cannot subclass a Swift class in Objective-C. Taken from Using Swift with Cocoa and Objective-C.
So yes, you can use the ABCTableViewController as a @property for composition, but you cannot inherit from it.

S2dent
  • 871
  • 6
  • 9
0

I found problem in project structure. I don't know why, but project contains unused ObjC++ source .mm and in this situation compiler ignore project settings and also doesn't generate modules.

helpful and related page: use of @import when modules are disabled

Community
  • 1
  • 1