Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a framework with Objectivec files and Swift files

I have a Xcode project with Obiective-c files and swift files, Now i want to create a framework with both classes, Is this possible ?

like image 571
Mohamed Raffi Avatar asked Oct 23 '25 14:10

Mohamed Raffi


1 Answers

Yes, this is straightforward and the process is documented by Apple. Please read "Swift and Objective-C in the Same Project" with thought and you'll be wiser (the section "Importing Code from Within the Same Framework Target" covers importing Objective-C in Swift from the same target, and the other way). Briefly…

  • For framework targets you don't need to create a bridging header to make your Objective-C importable to Swift, you just need to #import those headers you want visible to Swift in the framework's umbrella header. For that to work, the header needs to be marked public.
  • For Swift to be importable in Objective-C in the same framework target, make sure "Defines Module" is toggled on for the target, and in the files where you need to reference the Swift types, do an import in the style #import <ProductName/ProductModuleName-Swift.h>. If I recall this right, the Swift types / methods / properties you want to access from Objective-C will need to have been declared public for it to be accessible to Objective-C code even if it's in the same target.
like image 70
mz2 Avatar answered Oct 26 '25 05:10

mz2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!