Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an importable module in Swift?

Tags:

module

swift

I have read through Apple's documentation for Swift and can find nothing about how to create modules or how to define class or stucture members as private or public.

There are references to the import statement in the syntax but I can find no information on what it does or how to use it.

Does anyone know where I can find this?

like image 568
sprinter Avatar asked Jun 04 '14 00:06

sprinter


People also ask

How do I create a custom framework in Swift?

In the app, select the project from the project navigator, select the Stocktance target, and scroll to Frameworks, Libraries, and Embedded Content. Click on the plus button, click Add Other… and select Add Files… Navigate to the SettingsKit folder and select it. We've added the framework to the project.

How do you make program modular in iOS?

Creating a module.Create a project and place it inside the workspace. Add the module's dependencies to the Podfile. Add the dependencies of step 2 into the pods of the app too. Run pod install and compile the module to make sure it can use the external dependencies.

How do I create a Swift package?

To create a new Swift package, open Xcode and select File > New > Swift Package. Choose a name and select a file location. Select “Create Git repository on my Mac” to put your package under version control. On completion, the Swift package opens in Xcode and looks similar to a standard Xcode project.


2 Answers

In Swift, "Modules" refers to Frameworks. Xcode now has a template for creating a framework project for both iOS and OS X.

There is currently no way to declare methods or properties public / protected. If you would like to see this added as a feature, you can make a feature request on Apple's bug reporter. It should also be noted that Apple has stated that the language could change with each release of Xcode, so it is possible that member access levels could be added before the public release.

like image 93
Austin Avatar answered Sep 21 '22 06:09

Austin


Also, there is a way to make a module by yourself, but it's a bit harder way.

If you'll look at xcrun swift -help you may see a few options, and there are -emit-module, -emit-library and -emit-object which might be useful, but, probably, you should prefer official way and distribute modules via Frameworks.

If you still want to make module on your own, you can read this guide with some explanation

like image 26
AlexDenisov Avatar answered Sep 19 '22 06:09

AlexDenisov