Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: import framework but can't find class in it

Tags:

xcode

ios

swift

I import a swift framework to a swift project, but when I call the class in this framework, Xcode throw a compile error "Use of undeclared type 'xxxx(class name)' ".

I feel Xcode have found the framework, otherwise it will complaint "can't find xxx(framework name)".

But why Xcode can't find the class of this framework.

I have tried remove and re-add framework, and delete DeivedData files, but all of them not work. I haven't use CocoaPods to import framework.

Any idea?

like image 347
Cindy Avatar asked Jul 06 '17 03:07

Cindy


2 Answers

In a Framework that was built for Release (and not Debug), the class symbols need to be accessible.

Make sure you are you trying to access Public or Open classes from your Swift framework.

// set the Framework class to Public
public class rnHello{  

    // set the initializer to public, otherwise you cannot invoke class
    public init() {  

    }

    // set the function to public, as it defaults to internal
    public static func world() {  
        print("hello from a static method")
    }
}

Now you can access this via your Swift code or if you attach lldb using:

lldb) po rnHello.world()

like image 196
rustyMagnet Avatar answered Nov 14 '22 23:11

rustyMagnet


Make sure that the FrameWorkSearch path in the BuildSettings of the project is reflecting the correct path to your framework.

like image 38
tendstoZero Avatar answered Nov 14 '22 22:11

tendstoZero