Swift: using private framework
Asked Answered
U

2

12

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?

Unfeigned answered 17/3, 2015 at 11:0 Comment(5)
is the class marked as public? you must have something like public class className {...}Substrate
Did you manage to resolve the issue?Flour
Actually no, but I didn't spent time over itUnfeigned
I have added answer. This will be surely. Please checkMarco
you can make a fat library , you can see this link : https://mcmap.net/q/16088/-swift-framework-build-fails-for-device-but-not-for-simulatorFremantle
R
1

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.

Reba answered 13/10, 2015 at 22:35 Comment(1)
From his description, it doesn't sound like he's working within the same workspace for framework and project.Ossian
S
0

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.

Spontaneity answered 1/9, 2016 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.