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

Viewed 8197

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?

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()

Related