Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import framework for whole project at one place in Swift?

I made an own Cocoa Touch Framework, and I want to import it only at one place in the code. In Xcode / earlier in Objective C there were a central location under Supporting Files. How does it work for Swift based project?

like image 670
János Avatar asked May 11 '15 08:05

János


People also ask

How to create a swift app in Xcode?

In some Xcodes, you will find the option as Cocoa Touch Framework. Name your Product and select the language as Swift. Click Next. Save the project in your desired location and click Create. Now, we will add one more file to our Project. Right-click on your Project present on the left-hand side with the blue icon and select Add -> New File.

What is a package in Swift?

A package consists of Swift source files and a manifest file. A package is a collection of Swift source files. If you are using Swift Package Manager you also have to provide a manifest file in order to make a real package. If you want to learn more about this tool, you should check my Swift Package Manager tutorial. Example: this is your package:

What does import mean in Swift?

With the import keyword you are literally importing external modules into your sorce. In Swift you are always using frameworks as modules, but let's go back in time for a while to understand why we needed modules at all.

What should I learn in Swift?

Learn everything about Swift modules, libraries, packages, closed source frameworks, command line tools and more. First of all you should have a clear understanding about the basic terms. If you already know what's the difference between a module, package, library or framework you can skip this section.


1 Answers

Create a Frameworks folder. Drag and drop your framework in it. Then create a bridging header file (easiest way to do this in Swift project is by adding an objective c class and it will ask you to create that bridging file for you). Then in your bridging header file just add

#import <YourFramework/YourFramework.h>

Then your framework classes are accessible from Swift. Hope this helps!

like image 114
Valentin Avatar answered Sep 23 '22 08:09

Valentin