Antonio Romano
Antonio Romano

Reputation: 285

Swift: using private framework

I have built an iOS Swift framework with Xcode.

After writing the code I have build the project and took the .framework file inside the Products folder to test it.

To test the framework have open a new application and drag and drop the .framework file previously built and I added it into the embedded binaries list of my application project.

To import it into my ViewController.swift class I wrote:

import frameworkName

No problem until here, this means that the project sees the framework. When I try to use a public class inside the framework with:

var x : className?

I get the following error:

'className' is unavailable: cannot find Swift declaration for this class

What does it mean? What is the problem?

Upvotes: 12

Views: 2893

Answers (2)

Chen Wei
Chen Wei

Reputation: 521

To actual a self defined framework, u really have to do a lot of things.

Firstly, make sure ur framework is used on right device. It's to say framework can only be used on corresponding device(either one of Simulator, Device and Mac). In other words, if framework A built on simulator, project import framework A can only pass compile and successfully built on simulator.

P.S. if universal version desired, -lipo command is what u need to further explore.

Secondly, during implementing ur framework , make sure all the classes, methods and variables u want use outside start with Public.

Thirdly, check ur project setting Embedded Binaries and linked Frameworks and Libraries do contain ur framework.

Upvotes: 0

user4691305
user4691305

Reputation:

When you're referencing a framework in the products directory from your workspace, ensure that the location is "Built Products" and the filename is just the framework name, without any additional path components.

If you're referencing a framework that isn't in your workspace, I would recommend using Carthage instead of copying it directly into your repository. This will make versioning much easier, and will ensure that it is built correctly for both simulator and device.

Upvotes: 1

Related Questions