4

Is it possible to explicitly declare that a Swift source file isn't included in the Objective-C Generated Interface Header? As an example, let's say I have this Swift class

class MyViewController: UIViewController {
}

In my MyApp-Swift.h generated header, I see this

SWIFT_CLASS("_TtC4MyApp16MyViewController")
@interface MyViewController : UIViewController
- (nonnull instancetype)initWithNibName:(NSString * _Nullable)nibNameOrNil bundle:(NSBundle * _Nullable)nibBundleOrNil OBJC_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder * _Nonnull)coder OBJC_DESIGNATED_INITIALIZER;
@end

However I would prefer this class isn't exposed to Objective-C. I'm working in a larger app, and our generated -Swift.h file is well over 8,000 lines. This ends up making incremental builds painful when something that should only require a recompilation of the Swift code ends up causing a recompilation of the Objective-C code as well simply because this header file changed.

@nonobjc sadly does not work. I receive the error '@nonobjc' attribute cannot be applied to this declaration.

bclymer
  • 6,679
  • 2
  • 27
  • 36
  • Why you market it public then? – Cy-4AH Oct 03 '19 at 09:31
  • @Cy-4AH I've clarified by removing `public` from the question. In that context, `public` is declaring that it is visible outside of its module. It has no relation to whether or not it should be exposed to Objective-C via the generated header. But just in case I did validate that after removing `public` in this specific example, it does still appear in the generated header. – bclymer Oct 04 '19 at 14:12
  • I think you can't make it @nonobjc if you have one of your method with @objc. This is always true when you create a custom `UIButton` or `UIGesstureRecognizer` and need a method to respond to those actions. – SaintTail Dec 22 '20 at 15:33

0 Answers0