Reputation: 395
How do I import a Swift class from a framework?
TestClass
in that Cocoa touch framework import FrameWorkTest
The application project compiler can't find TestClass
.
How can I import TestClass
for use in the main application?
It says that TestClass
is not defined. I also want to add an extension in FrameWork an then use it.
https://github.com/ArtemKyslicyn/-SwiftImportFrameworkTest
I'm using this Tutorial http://www.swift-studies.com/blog/2014/6/30/creating-a-pure-swift-framework-for-both-ios-and-mac
I'm on Xcode version 6.0 seed
Thanks
Upvotes: 14
Views: 16487
Reputation: 1624
To import a Swift class from a framework:
Go to your Project -> Build phases -> Select test target -> Link Binary With Libraries -> + Button -> Add other (on the dialog) -> Select your framework and congrats!
I leave the explanation in images below:
Upvotes: 0
Reputation: 395
Here's one solution I found:
+
to add targetcocoa touch framework
project
and press add dependency
and add framework
I used the solution here: https://github.com/ArtemKyslicyn/-SwiftImportFrameworkTest in the project named AddingFrameWork
Upvotes: 3
Reputation: 8372
Make the class in framework public. Also any variables must be public if you want them to use outside the framework.
public class MyClass... {
...
}
Upvotes: 38
Reputation: 2126
@Artem Kislitsvn: I did see your github repository,
In which you have TestClass.Swift file outside the targets 'test' and 'FrameWorkTest'. Which is out of the scope of the namespaces.
In Swift the namespaces are specified per targets. In your case 'test' and 'FrameWorkTest' are two targets. If you keep your file out of the targets, then your class(.swift file will not visible to at any time).
The solution is very simple. You just move your TestClass.Swift file inside any of the target groups (Drag and drop through Project explorer).
Following this your project works...!
Upvotes: 0