0

I am having an issue using a custom pure Swift framework in another project.

Some notes (as I've believe I've thorougly searched for all possible answers) :

  1. I have my classes declared as public in the framework.
  2. I have successfully built and ran the framework with a Swift target application but only from within the framework project.
  3. I have included my framework in Linked Framework and Libraries and Embedded Binaries.

What i am trying to do is build a pure Swift single view application project by importing only the product framework. The error I am getting is "MyClass is unavailable: cannot find Swift declaration for this class" (which as mentioned above is public) . Also I have an public enumaration with a similar error: "Use of undeclared type 'MY_ENUM'" Example code below:

import Foundation
import UIKit
import MyFramework /// don't know if this is needed.

public class ViewController: UIViewController{
    var myclass:MyClass? ///here is the above error ,it's initialized in the viewDidLoad() function
    var myEnum:MY_ENUM = MY_ENUM.MY_ENUM_VALUE /// 2nd enumeration error.
    override public func viewDidLoad(){
        super.viewDidLoad()

     self.myClass = MyClass(arguments) ///same error as above
     self.myClass?.myFunction  /// ViewController does not have a member 'MyClass' error
     /// more code here with errors regarding the class and enum.
}

I've also tried using an objective-C Bridging Header (though I believe this is wrong) and importing my framework header.

#import <MyFramework/MyFramework.h>

Is it possible for a solution to the above or is a restriction from Swift and I am trying something in vain?

One final note: I've included some other headers from another Objective-C framework in my framework because it was the only way to build it as a custom Swift framework. The classes there are visible to the Swift application.

P.S.If more code is needed I'll be happy to provide.

2 Answers 2

1

Solved the issue.

Had to put the .swift files together with the .h files as public headers in my custom framework (don't understand why though) and build again.

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

2 Comments

You mean in Build Phases? Did you add something to your framework header file? Doesn't seem to work for me.
Been ages since I last did this , but if I recall correctly , just put the .swift files through drag and drop in the .framework folder in Xcode explorer and also add them in the build phase just to make sure.
0

Maybe the path of your framework is wrong?

3 Comments

I import the framework by drag-&-drop. It's not red in the project navigator so I don't think that's an issue.
@2mytrompess Emm...Did you check your Build Sitting?The framework search path?
If you are referring to the framework search paths in the build settings ,yes it's the correct. Though now there are multiple paths because I've been trying importing and deleting several times. Also as I've said in my post , the target App can see other classes which are declared in the headers of my framework. Those classes though are Objective-C code and I did not create them . I had to put those headers in my Swift framework project and not only include the 3rd party framework I've used if I wanted mine to be built without errors. The issue is with my Swift classes.

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.