2mytrompess
2mytrompess

Reputation: 11

using custom Swift framework in another Swift project

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.

Upvotes: 0

Views: 1088

Answers (2)

2mytrompess
2mytrompess

Reputation: 11

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.

Upvotes: 1

Lau Cherish
Lau Cherish

Reputation: 101

Maybe the path of your framework is wrong?

Upvotes: 0

Related Questions