3

Background

Let's say project App is a 50/50 mixed Swift/Objective-C codebase. Objective-C files import some Swift via auto-generated "App-Swift.h" file.

#import "App-Swift.h"

Recap on How it Works

"App-Swift.h" file automatically includes all the Swift's classes inherited from Objective-C ones: NSObject, UIView, UITableViewCell, UIViewController, etc; and of course all the @objc and @objcMemmbers attributed things.

The Issue

When anything is added to the "App-Swift.h" - all the Objective-C files that import it - have to be recompiled. Even if what was added to Swift is actually not used in any of Objective-C files, but we just inherited from, e.g., UIView.

It all adds up when you import "App-Swift.h" into many files and it slows you down.

Possible Proper Solutions

Break down the codebase into small modules, so interface segregates; avoid NSObject inheritance; Convert as much Objective-C to Swift as possible; private all @IBOutlet, @IBAction during development; etc.

The Question: Cutting a Corner

Is there a way to disable Swift to Objective-C bridging header ("App-Swift.h") auto-generation (but keep the last generated App-Swift.h) at least manually via any of Swift compiler flags?

Any other quick win ideas here?

Related References Revised

Swift and Objective-C interoperability
https://dmtopolog.com/code-optimization-for-swift-and-objective-c/
https://swift.org/blog/bridging-pch/
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c

Going into modules
https://blog.griddynamics.com/modular-architecture-in-ios/
https://www.bignerdranch.com/blog/it-looks-like-you-are-trying-to-use-a-framework/
https://www.bignerdranch.com/blog/it-looks-like-youre-still-trying-to-use-a-framework/

tar500
  • 171
  • 2
  • 8
  • "It all adds up when you import "App-Swift.h" into many files and it slows you down" Interesting. So what if you import it into the precompiled header instead? – matt Sep 23 '20 at 01:08

0 Answers0