Swift: using private framework

2019-03-18 14:35发布

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?

3条回答
疯言疯语
2楼-- · 2019-03-18 15:01

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.

查看更多
Lonely孤独者°
3楼-- · 2019-03-18 15:08

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.

查看更多
老娘就宠你
4楼-- · 2019-03-18 15:18

If you created fat binary with 'lipo' tool, don't do that.

It works fine with separated framework.

I have to find another binary combine tool other than lipo

查看更多
登录 后发表回答