0

I have gone through many questions on Stack Overflow and Apple documentation, and many more related to it. Not able to solve it. Thanks in advance for any help. Done the following steps:

Framework:

  • I have Objective-C framework
  • Adding Swift files to the framework
  • Bridge files do not go with framework, but we do have $(SWIFT_MODULE_NAME)-Swift.h file generated. Framework needs <ProductName/ProductModuleName-Swift.h>
  • Swift class should be public (tried with @objc as well)
  • Swift method should have @objc (tried with setting public as well)
  • Framework header file should be public at Identity attributer

Usage:

  • Need to import the above file in any .m file where we want to use Swift files in Objective-C code.
  • Forward declaration of Swift class in Objective-C class
  • Defines Module in build setting should be set to yes
  • Always add embed swift standard libraries to yes in build settings

Still getting error for Swift class:

framework's header.h is not found in umbrella header.

Note: ProductModuleName-Swift.h file is recognized in header file but not in implementation files. But I am able to use Swift classes in objective c classes.

Update: Error is when I am creating the framework with git repository. Without repo I am able to build my framework successfully. As per my understanding git should not create any issue. Digging into it.

  • I tried to clean up your question to understand what exactly you did, but still didn't understand some parts. Few tips: 1. Make sure that every Swift class and every method you want to use from Objective-C **is public and is defined as `@objc`**; 2. Make sure you are importing `-Swift` class using correct syntax: it may not be `#import `, but rather `#import "ProductName/ProductModuleName-Swift.h"` - depends on your settings – timbre timbre Jan 23 '21 at 22:51
  • As per Apple document, to include in -Swift file for framework as the target, you need to import -Swift file as https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c What settings should I look for to understand the type of import? – Sonam Sodani Jan 23 '21 at 23:15
  • the bracketed import you have is _usually_ the right way to import framework (standard cocoapods, or drag & drop would work that way). I was just saying (since I don't see your project setup), make sure it's the right way for your setup. A good read on this topic is here: https://stackoverflow.com/questions/1044360/import-using-angle-brackets-and-quote-marks – timbre timbre Jan 24 '21 at 03:23
  • If i understand correctly your framework and application using it are int 2 different workspaces. What I would try to do first, is get unit test inside framework module to use that Swift class from Objective-C test. I.e.: create an MyTest.m class, import `` and see if yo can get to function in Swift class. Get that to work first and you will understand what the problem is – timbre timbre Jan 24 '21 at 03:27
  • @KirilS. thanks for your help. I was able to solve the issue. The header search path was different than the header path of the Swift-h file. I am having 3 targets in my project. For other two it was working fine but the target for creating framework was not able to find the Swift-h file. After changing the header from $PROJECT_NAME to $CONTENTS_FOLDER_PATH, it worked fine. – Sonam Sodani Jan 30 '21 at 08:03

0 Answers0