Swift FAQs

These Frequently Asked Questions are for those starting to learn Swift. As I start my journey I have a lot of questions. I'm documenting those here from the perspective of someone who has been programming for a long time in Python and has worked in other languages when needed (e.g. bash, Groovy, Go, PowerShell, etc.).

What is Swift language, standard library, and Foundation?

Swift language

Swift is a general-purpose programming language built using a modern
approach to safety, performance, and software design patterns.

Standard library

The Swift standard library defines a base layer of functionality for
writing Swift programs.

Foundation (Foundation Project) is a framework.

The Foundation framework defines a base layer of functionality that is
required for almost all applications. It provides primitive classes and
introduces several paradigms that define functionality not provided by
either the Objective-C runtime and language or Swift standard library and
language.

Think of these three things as layers. The language is the first layer just like any other language, say Python or Go. The standard library is the next layer which provides common functionality. Next layer is Foundation. As far as I understood it, what is for example the standard library in Python is divided into standard library and Foundation in Swift. From this answer I take it that there is a legacy of macOS and Objective-C that is bridged with the new world of an open source, multi-platform Swift language.

Foundation has two implementations, one for Apple platforms (think of it as native Foundation) and one for non-Apple platforms (think of it as cross-platform Foundation). Both should provide the same functionality but are targetted to different use cases.

Listen to Where is Swift headed in 2022? for more information on the relationship of these three.

Do I need to learn SwiftUI or UIKit to learn Swift?

I think the answer is: No. Swift is a language and ecosystem (see above) which is not limited to building apps for Apple platforms. It's a general purpose language and the community is working hard to make it usable in many scenarios.

When building apps for Apple platforms (iOS, macOS, etc.) you must use SwiftUI (or UIKit, if you desire).

Unfortunately, when searching for tutorials and guides on Swift, the vast majority of results are about building apps. If, like me, you want to learn Swift first (and maybe build some toy tools), those guides are the wrong place to start. I am still searching for good guides to help a backend programmer get started with using Swift to solve real life solutions.

What is Dispatch?

Dispatch, also known as Grand Central Dispatch (GCD), contains language
features, runtime libraries, and system enhancements that provide systemic,
comprehensive improvements to the support for concurrent code execution on
multicore hardware in macOS, iOS, watchOS, and tvOS.

It is available on Apple platforms and Linux.

Project Status

A port of libdispatch to Linux has been completed. On Linux, since Swift 3,
swift-corelibs-libdispatch has been included in all Swift releases and is
used by other swift-corelibs projects.

Can I cross-compile Swift for other platforms?

It does seem possible but it appears the experience is not as smooth as what Go provides. The major reason is that the libraries (see above) you use will determine which platform your application can be built for.

Can I build a single binary like in Go?

It does not appear that Swift supports the same experience as Go does today. Swift can build a statically linked binary on Linux and work in underway to enable static linking on Windows.

Is there a library like Python requests?

Foundation (see above) has networking primitives which can be used. Namely, the URL Loading System. The cross-platform port may have varied implementation status for the different entity names.

If I were replacing my Python scripts (that use the requests library) with Swift applications, I think I would be able to. I have not tried that yet though so I can't say how smooth the experience is.

Is there a library like Python argparse?

Yes. It is called Argument Parser.

Is there a library like Python unittest or pytest?

Yes. It is called XCTest.

Are there cloud SDKs?

AWS SDK for Swift exists today but is in Developer Preview at the time of writing.

Azure has iOS SDK but not like AWS.

This is one area where Python and Go have far better support from major cloud service providers.