4

Swift has an interesting keyword, which can be declared in the ModuleA:

@_exported import Foundation

Then, when in some other module (e.g. ModuleB) I import the ModuleA:

import ModuleA

let currentDate = Date() // using a Foundation struct

... I'm able to use also the types from the Foundation even though I'm not importing it with an import statement. It's being automatically imported as it has been declared as @_exported in the ModuleA.

Now I'd like to have a similar behavior in Objective-C.

Given:

  • 3 Targets: TargetA (Swift), ProtocolTarget(Swift with @objc keyword annotated types) and TargetB (ObjC)
  • I'd like to make the ProtocolTarget implicitly imported, so that when the TargetB imports TargetA, all of the methods from the ProtocolTarget should become also available inside the TargetA.

How can I achieve this?

Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
  • 1
    You would just import the headers for `ProtocolTarget` into your umbrella headers for `TargetA` and `TargetB`. See how `Cocoa` does it for example (it imports the headers for Foundation, AppKit, and CoreData) – Alexander Aug 23 '22 at 12:20
  • Could you please pinpoint to the file of "how Cocoa does it"? – Richard Topchii Aug 23 '22 at 12:40
  • Command click on the `Cocoa/Cocoa.h` in `#import ` in one of your Objective C files – Alexander Aug 23 '22 at 13:25
  • Are you restricted to use modules only? If not, why not just rely on transitive `#import` expression? – The Dreams Wind Aug 23 '22 at 15:49
  • Updated my question. Actually, I am restricted to modules only, since the `ProtocolTarget` turned out to be a Swift target with `@objc` annotated keywords. Now I'd like to achieve a behavior similar to how Swift modules work. – Richard Topchii Aug 24 '22 at 09:17

0 Answers0