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
  • Did you import the module of ABCTableViewController in the Swift file XYZTableViewController? Commented Sep 6, 2016 at 1:43
  • yes I have imported right module on the top of source file import ABCKit Commented Sep 6, 2016 at 7:12

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You can implement a Swift protocol in Obj-C, so that is another option possibly.
I know about that limitations, but that is generated header file with class definitions. I don't define class myself.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.