Swift umbrella from another target

I have a project with multiple goals. The main goal is to combine Swift and Objective-C classes and objc files that use Swift classes, including the ModuleName-Swift.h probe header. However, when I include the same source files in multiple targets, the umbrella header cannot be found other than the main target. The module name in the header import must be different for each target. How do you achieve this?

Update:

So far, I haven't found any other way other than to set the same product module name for all targets. This has no side effects.

+3


source to share


1 answer


I have the same problem while writing a Today Extension for my application. I have a file named for example Items.swift located in the Today Extension component and included in this target. Therefore, I have the following situation: the main project is completely written in Objective-C and today the extension is written in Swift

Problem:

I want to include Items.swift file in my main project and use it

Decision:



  • Make sure to be Items.swift

    included in the main target of the application.
  • Important ( !!! ), you must create "ProductModuleName"-Bridging-Header.h

    and add a link to this file in the project file (Objective-C Bridging Header) even if your main target contains only Objective-C code
  • Yours Items.swift

    must inherit from NSObject or its descendants
  • Then add #import "ProductModuleName-Swift.h"

    to place where you want. to use Items.swift

    and click "Build"

Finally you can go to "ProductModuleName-Swift.h"

and make sure the interface is generated than you can use the Objective-C version of your class

ProductModuleName which you can see in build settings -> Packaging -> Product module name

+1


source







All Articles