Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.


Swift frameworks and modules

I have been busy creating a SSL library that sits on top of SwifterSockets.

And that uses OpenSSL to do the secure work.

Since the Swift Package Manager (SPM) was included in Swift 3, why not use it and make some nice and clean packages of SwifterSockets and the SSL variant: SecureSockets?

Should not be too difficult ... right?

Now difficult and difficult are two different things ... No it is not difficult to make packages. But the marriage of SPM and Xcode is not too great. Kind of sucks really...

But the good news is it can be done.

The SPM lives at the command line. Outside of Xcode projects. While it is possible to use the same code in both the SPM packages and Xcode projects, there are some caveats.

Before we dive into this, it is first important to know about frameworks and modules.

Modules are an invention to skip on configuration.

When we use frameworks without modules between projects, it will be necessary to configure bridging headers and search paths. Modules can be used to skip all that.

To create a Modular Framework all we need to do is to generate a module.modulemap inside a framework. And that is not too difficult, since Xcode will do it for us if we set the "Build Setting" "Defines Module" (in subsection "Packaging") to 'Yes'. Of course the target should be a framework, it makes no sense for app's (or so I would think...).

With Modular Frameworks we no longer have to create bridging headers or configure search paths. Simply add them as "Embedded Binaries" (for dynamic libraries).

In the next blog I will show you how I changed SwifterSockets from an Xcode project to a SMP Package.

Happy coding...

Did this help?, then please help out a small independent.
If you decide that you want to make a small donation, you can do so by clicking this
link: a cup of coffee ($2) or use the popup on the right hand side for different amounts.
Payments will be processed by PayPal, receiver will be sales at balancingrock dot nl
Bitcoins will be gladly accepted at: 1GacSREBxPy1yskLMc9de2nofNv2SNdwqH

We don't get the world we wish for... we get the world we pay for.

No comments:

Post a Comment