8

I have a custom Framework that has a bunch of Objective-C Classes. Within the Framework, I'd like to add more classes using Swift. However, when trying to expose the Swift classes to the Objective-C code using: MyProduct-Swift.h, it comes up as "MyProduct-Swift.h file not found".

I've tried this in a single view template and it works fine. Is it not possible to import Swift within a framework?

I've also verified that I have set the Defines Module setting and the Module Name. I've tried it with and without these settings.

4
  • Is that your only compiler error? The header isn't generated if the Swift code doesn't compile. Commented Jun 9, 2014 at 21:50
  • @SteveWaddicor All I'm doing in the Swift code is declaring a custom class. And ya, that's my only compiler error. Commented Jun 9, 2014 at 22:26
  • I am getting the same error.. =( Commented Jun 10, 2014 at 20:48
  • Actually there is no ability to import swift files for now because it's required to add class header into the list of published headers. Swift files from the framework does not produce such headers... for now. Commented Sep 13, 2014 at 21:33

2 Answers 2

14

I found some additional steps to make it all work. In addition to setting 'Define Module' to YES and 'Product Module Name' (usually these are set correct by default if you create new touch Framework in Xcode 6) you also need:

  1. add 'public' keyword to all Swift classes you need in Objective C
  2. you need to add 'public' keyword even to all the methods and properties within the class that you want to access from Objective C
  3. You need to import Swift header in a 'long' way like this:

#import <ProjectName/ModuleName-Swift.h>

Sign up to request clarification or add additional context in comments.

1 Comment

How can we expose internal swift class in Objective-c without making it public?
4

Ok, I found what the problem is.

Make sure that in Build Settings - > Packaging you have Define Module set to YES and Product Module Name is set as well. Then in the storyboard file the name for the Module should be the same and match what you have in your Build Settings. Then in your Obj-C file write include "-Swift.h"

That did the trick for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.