I have made an Xcode Swift project ("Project1"). In a new project ("Project2"), I have trouble adding project 1.
I have tried adding project 1 to project 2's build phases (target dependancies, compiled sources, link binary with libraries); didn't work. When adding to the compiled sources, it wouldn't work no matter which option I chose (folder references, groups, copy if needed).
I get no compiler errors at:
import Project1
But when I try to use a class from project 1, I get the error "Use of undeclared type".
I have also tried to following links with no success:
Both projects are in Swift (iOS).
I'd be very thankful if someone helped me with this issue.
Update: Project 1 is not a framework - it's an iOS app. I need to use some of its classes in project 2. The problem is that project 1 uses the Objective C library Common Crypto via a bridging header. When I manually add project 1 classes into project 2, I get an error ("unresolved identifier") in the project 1 Swift code that uses Common Crypto.
So in a nutshell: I have an iOS app (project 1), which is in Swift but uses Common Crypto via bridging header. When I add a number of classes from project 1 into project 2, it cannot resolve the references (in project 1) to Common Crypto variables.
Edit: As you have CommonCrypto as a dependency you will have to add the module
to your Project2 project instead to solve your issues ( this is the easiest without resorting to an umbrella framework ). Add a run script build phase
and include http://pastebin.com/1vmiqffu
-- Credits: Script 'stolen' from: https://github.com/henrinormak/Heimdall
Ok so I'm going to assume here that Project1
actually has a framework as a target. What are the access permissions set on the types you are trying to use ?
Here are a couple of catchya's with Swift and frameworks as I encountered them:
ModuleName.h
). This also means these will be available to whatever project you import them to. As far as I know you need to use a module.modulemap
in order to make use of private headers and includes. Swift
Classes / Structs / Definitions in general are internal by default. It is a very good design choice and it forces you to think about the access rights on every component you write. Keeping things private by default makes it easier to only open stuff that really needs to be open ( public, open ), allowing for easier code maintenance since you know that private things are only accessed within the same context. ( Otherwise: error ) For some more assistance this link might be of help to you on how to do some fundamentals:
Assuming Project1
is a Framework and Project2
is an application using the framework:
Workspace
(Xcode File -> new -> Workspace) named TestWorkspace
Finder
, drag the Project1.xcodeproj
file to the TestWorkspace
Finder
, drag the Project2.xcodeproj
file to the TestWorkspace
, above Project1
Edit your TestWorkspace
schemas Build
setup:
Project1
and Project2
Project1
is above Project2
Project1
is build first Project2
s target -> General project1.framework
(in Products
group) to "Linked Framworks and Libraries" Note: To be visible for the client, all classes and methods in your project1.framework have to be public
or open
. Finde detailed information in Apples documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.