Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS import swift class from swift using framework

How do I import a Swift class from a framework?

  1. I have Xcode Workspace
  2. I create a Cocoa touch framework with using Swift
  3. I create a Swift class named TestClass in that Cocoa touch framework
  4. I create a Tabbed Base iOS application
  5. I import my framework in that tabbed iOS application using 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

like image 251
Artem Kislitsyn Avatar asked Sep 16 '14 10:09

Artem Kislitsyn


2 Answers

Make the class in framework public. Also any variables must be public if you want them to use outside the framework.

public class MyClass... {
 ...
}
like image 92
Alexander Volkov Avatar answered Oct 16 '22 12:10

Alexander Volkov


Here's one solution I found:

  1. Create new iOS project
  2. Press on project
  3. Press + to add target
  4. In the resulting window, choose cocoa touch framework
  5. Press on project and press add dependency and add framework
  6. Success!

screenshot illustrating the success

I used the solution here: https://github.com/ArtemKyslicyn/-SwiftImportFrameworkTest in the project named AddingFrameWork

like image 29
Artem Kislitsyn Avatar answered Oct 16 '22 12:10

Artem Kislitsyn