Popular Open Source Projects for Swift Development

On December 3 2015, Apple officially open sourced the Swift programming language. By open sourcing the entire programming language, Apple has now allowed developers from all over the world to contribute to the language and assist in its development and evolution. In addition to this, the Swift programming language can now be used in environments outside of Apple's platforms, such as Linux.

In this article, I am going to be telling you about some of the most popular and interesting projects that utilize Swift and will, over time, evolve alongside the language itself.

1. Foundation

If you have done any iOS programming before, especially using Objective-C, you are probably familiar with classes such as NSDate, NSArray, NSString, and NSURL. These classes are all part of the Foundation framework, which is available on every Apple platform (iOS, OS X, tvOS, and watchOS).

The basic functionality the Foundation APIs provide, however, is also being reimplemented as a Swift Core Library by Apple in order to be portable across platforms. This project can be found at Apple's swift-corelibs-foundation repository at GitHub.

Numerous other developers are actively working to bring the Foundation APIs to Swift in a portable cross-platform way. The most popular of these projects is SwiftFoundation which, at the time of writing this article, has many key differentiators from Apple's implementation.

More Functionality

It provides more functionality. As the project's README notes, many methods in Apple's Foundation project are marked with NSUnimplemented(), meaning that only basic functionality is currently available.

Portability

From the very beginning, it has been designed with portability in mind. Unlike Apple's Foundation core library, SwiftFoundation doesn't rely on the CoreFoundation APIs written in C. This allows for SwiftFoundation to more easily support a wider range of platforms in the future.

Protocol-Oriented

SwiftFoundation has been entirely designed and developed using a protocol-oriented structure rather than the more traditional object-oriented programming style. Doing so offers a range of benefits, which you can learn more about in this tutorial.

More importantly, it completely modernizes the 20+ year old Foundation APIs. Apple could eventually do something like this with their Foundation core library but the README of their repository states the following.

In our first year, we are not looking to make major API changes to the library. We feel that this will hamper the primary goal [of portability outside of Apple platforms].

Both of these projects are actively being updated and will definitely become crucial in the future of Swift development as they allow for basic functions, such as networking, getting/manipulating dates/times, and persistent local storage on any platform supported by the Swift language.

2. Other Core Libraries

In addition to Foundation, Apple is also redeveloping from the ground up two other major libraries to be used with Swift on other platforms: XCTest and libdispatch (also known as Grand Central Dispatch). While these projects aren't quite as popular or have the same scale as Foundation, they are still very important when it comes to Swift development.

The XCTest project is designed to allow developers to create unit tests for their Swift code. If you aren't familiar with unit tests, then take a look at this article to learn more about them. While in its very early stages with only basic tests being supported, the XCTest project will, over time, become very important to all Swift developers when testing and debugging their code.

The libdispatch project allows for concurrent (multithreaded) workflows when running on supported hardware. This is particularly important for actions, such as network requests, so that the main thread doesn't get blocked by other operations.

While both of these repos are owned and maintained by Apple, like Swift, they have been open sourced to encourage developer input. I encourage you to have a look at them, even if it's only out of interest to look at the implementation of the APIs. There's a lot you can learn from browsing the source code.

3. Web Servers & Websites

One of the most exciting possibilities of open sourcing Swift is the ability to use it as the primary programming language for server backends and websites. While HTML and CSS will remain the standards for the web in terms of presenting content to the user, once Swift and its libraries are mature and functional enough, Swift could be used in almost any situation where currently other languages, such as PHP and JavaScript, are used.

This is particularly exciting for Cocoa developers because the skills and knowledge they have already gained by using Swift for frontend development will then greatly assist them if they want to do backend development.

There are many projects that are all working to bring Swift to the web, including Vapor, Zewo, and Caramel. The most advanced and feature-packed of these projects, however, is Perfect.

Perfect encompasses many different Swift components, which each have their own unique purpose.

  • PerfectLib contains the networking APIs and utilities needed by both the client and server, including simplified HTTP request handling, JSON parsing, and other data management.
  • Perfect Server runs on server-side and handles accepting connections, processing requests, and returning responses. A server utilizing Perfect Server can use either FastCGI or stand-alone HTTP.
  • Various connectors that allow a server to extend its functionality and work with other APIs, including mod_perfect for FastCGI connectivity with Apache 2.4 and MySQL, PostgreSQL, and MongoDB for working with these types of databases.

When combined, these components allow for a fully functional web server, which would work exactly the same as a traditional server powered by PHP or JavaScript would. The possibilities of web servers running Swift is very exciting and projects, such as Perfect, are paving the way for the day Swift can be used for virtually every component of a project.

4. Swift Package Manager

If you take a look at the repositories mentioned earlier in this article, you will notice that some of them, in their root directory, have a file called Package.swift. Projects that contain this file do so in order to be used with the Swift Package Manager.

The Swift Package Manager is a dependency management system that is similar to CocoaPods and Carthage, enabling developers to link to third party libraries and use them in their own projects.

This package manager is being developed so that any platform using Swift can link to and import code in the exact same manner, rather than relying on a platform-specific solution. The Swift Package Manager is still in it's early development stages with many specifications subject to change. But it is aimed to be finalized and released alongside Swift 3.

If you'd like to take a closer look at this project and learn how to utilize it in your own code, then I recommend visiting the project's page on Swift.org or the repository on GitHub.

5. Miscellaneous Utilities

In addition to the aforementioned open source Swift projects, there are also many others that are very interesting and unique.

XCGlogger

This project is aimed at logging. It enables developers to print a lot more detail to the system console without having to write a whole bunch of extra code. This logging utility allows you to automatically log a variety of attributes, including thread name, source code file name, line number, and current scope method.

Swiftline

The goal of this project is to create command line applications with Swift. These applications support user interaction in the form of both regular keyboard input as well as multiple choice.

Swiftline would be particularly useful in an educational environment as students could use it to develop a fully functional and interactive application without needing to worry about any sort of user interface.

Swift Algorithm Club

This repository contains a wide array of useful algorithms all for use in Swift code. This includes things, such as fixed size arrays, hash tables, and shuffling. The repository contains a full list of all the currently supported algorithms.

Swift AI

Swift AI is an artificial intelligence project focussing on machine learning. The example project included in the repository shows how the AI system can learn to replicate a basic sine function.

Note that this project is currently only supported on iOS and OS X due to its dependency on Apple's Accelerate framework, which allows for improved performance when executing large calculations.

Conclusion

There are so many new and exciting open source Swift projects out there, which, over time, will develop and influence the careers of many developers. As you can see, by open sourcing Swift, Apple has not only allowed the language to become better through community contributions, but also to become useful when developing for platforms other than Apple's.

I encourage you to check out some of the projects mentioned in this article and look at what they are trying to achieve. If you want to look at even more projects, then I recommend browsing GitHub for the most popular and currently trending Swift repositories.

As always, leave your comments and feedback in the comments below.

Tags:

Comments

Related Articles