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 ?
Asked
Active
Viewed 1,429 times
4
-
Yes, it's possible. When you start doing that and have more questions, update your question please. – Eugene Dudnyk Jun 20 '17 at 18:09
1 Answers
11
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 declaredpublic
for it to be accessible to Objective-C code even if it's in the same target.

mz2
- 4,672
- 1
- 27
- 47