How to Learn Swift: Introduction
The Swift programming language was first conceived in 2014 and fore-fronted by Apple as a successor to their previously prevalent Objective-C.
Even though Apple adopted Swift as their flagship programming solution today, it is in fact an open source project that is maintained primarily by Apple.
If you are coming into this article with the assumption that Swift is solely for Apple’s platforms, you may be surprised to know that Swift is also being actively maintained for Linux distributions, and even Windows.
On the Linux side, the Swift compiler and surrounding dev tools support Ubuntu, CentOS and Amazon Linux distributions – that is to say you can develop Swift applications and deploy applications directly to those platforms; developing an Ubuntu application with Swift requires that you use the Ubuntu swift compiler. Likewise, you cannot compile a Windows app on Linux or Mac.
This setup is slightly different in Apple’s case however, where code can be compiled to all the platforms in Apple’s ecosystem, from iOS for iPhone to watchOS for the Apple Watch..
This multi platform support is handled by Xcode and the surrounding Apple toolkit that we’ll cover more of further down.
Table of Contents
Swift builds on Objective C and C-based languages
Swift was designed as a general-purpose programming language with the objective of replacing other C-based languages (C, C++, etc).
This was evidently a main goal of Apple, who are the main contributors and maintainers of the language. Although Swift is mostly used for front end development, it can also be used for server side processes too.
Swift attempts to solve the difficulties developers faced with the former, such as its steep learning curve partly caused by complex syntax and verbose conventions. In order to do this, Swift needed core characteristics to set it apart, such as being easy to learn, read and understand.
It attempts to do this by simplifying syntax, automating memory management and maximising efficiency.
Swift is faster than Objective-C with Apple boasting a speed increase of up to 2.6x over the latter on its home page. In addition, enhancements and API abstractions such as SwiftUI attempt to make coding UI a lot simpler by cutting down the amount of required boilerplate code.
Swift is the dominant Apple language, but lacks industry-wide adoption
According to the Stack Overflow 2020 Developer Survey, Swift lies in the upper bracket of the annual salary range, averaging at $58k globally and $125k in the United States (positions 11 and 9 respectively).
Interestingly, Objective-C is still very relevant; it boasts slightly higher figures in terms of salary, but the long term sustainability of this lead is doubtful given Apple’s efforts to standardise Swift as its preferred app programming language.
Even though Swift can potentially offer you a satisfactory salary, the popularity of Swift is lagging behind many other languages in the most commonly used. These small numbers reflect the exclusivity of Swift’s usage with Apple relative to the rest of the industry.
Although there are many good competitors to Swift (Go, Rust, Java, Scala, and even Python) each with their own unique features, Swift has a lot of potential room to grow outside of Apple’s ecosystem – if the programmer community sees value in doing so.
To catch up with the most recent programming language trends, refer to Iglu’s published piece outlining which languages you should be aware of in 2021 and beyond: Best Programming Languages to Learn.
This is not currently the case though, with CodingGame highlighting that Swift is falling in the ranks as the most loved language, as well as the language developers know best.
There are indeed advantages to learning Swift, but there is currently little incentive to do so outside of Apple’s platforms. As such, we’ll mostly focus on Swift’s prospects with Apple for the rest of this article.
How to Learn Swift: Prerequisites
For the purpose of developing iOS apps, macOS apps, and apps for other Apple devices, the following components are required.
Software: Xcode or Swift Playgrounds
Xcode is Apple’s IDE that comes with tight Swift integration out of the box. It is the central tool required for developing apps with the intent of publishing them on the App Store; it handles compilation, debugging, deployment to the Apple Developer Portal, and much more.
Swift Playgrounds however is specifically designed for learners; it is a lightweight Swift editor that allows you to see what you are coding, as you are coding.
Hardware: A Mac or an iPad
Production Swift apps are primarily developed in Xcode, but Swift itself can also be studied and experimented with on an iPad with Swift Playgrounds. Either device can be used as a way to become acquainted with Swift.
To see compiled Swift code running on a real device, owning your targeted device will give you further insight on how your Swift code performs. Whether you are coding for iOS, iPad OS, WatchOS, or tvOS having that device available to test your apps will ultimately aid in the learning process.
Swift Playgrounds hosts a range of interactive tutorials that are hosted by professional app developers. These projects provide a way to practice developing code that mimics real-world scenarios quite well, all within the Playgrounds app. The real-time environment provided allows you to see the results of your code as you are completing exercises.
Learning the Swift programming language outside Apple’s ecosystem
The Swift Language extension brings support to the popular VS Code IDE, so it is possible to learn and compile source code for Linux and Windows without having to invest in the iOS and wider Apple ecosystem.
Consult the Platform Support page on the official Swift website to see the other operating systems and deployable platforms.
How to Learn Swift: QA Round
Key questions surrounding the learning process of Swift will now be addressed, with valuable insights and tips along the way.
Why should I learn the Swift programming language?
There are two major reasons to learn Swift:
- If you have already coded apps with legacy APIs and would like to migrate to more relevant, future proof code.
- If you have not yet delved into iOS / iDevice app development and finding a way of doing so is something that interests you.
- If you do not yet have programming experience and wish to start learning one that is easy to learn, and with lots of educational resources available.
These reasons are again mostly Apple ecosystem centric due to Swift’s lack of adoption elsewhere.
As an entry level language and 2 billion+ iOS devices currently active globally, Swift does pose an attractive proposition to new software developers.
Developing iOS-supported React Native packages
If you are a React Native developer and wish to expand your skill set and your relevancy, learning Swift is a viable way of achieving those goals.
As is the case with all React Native packages that support native iOS functionality, the JavaScript being used on the React Native side must be binded with native iOS development APIs.
This native side to these packages are often hosted by the CocoaPods package manager, a dependency manager for Swift and Objective-C projects. CocoaPods should not be confused with Swift Package Manager – Swift’s own package solution that is integrated into the Swift build system.
Native Swift APIs are highly optimised and directly communicate with the device’s hardware.
This is ultimately what allows React Native applications to feel native; animations are just as fast and the UI just as responsive, because native APIs are still being executed.
Is Swift hard to learn?
It is one of the easier programming languages to learn, but still requires dedication and a structured learning process.
The ease of learning depends on a few factors; the main ones being:
- The documentation and educational content available online, whether that be great official documentation that is kept up to date, online video courses, in-person courses at educational institutes, community lead tutorials, sample projects containing up-to-date example code, or third party books in the publishing space.
- How much time you can dedicate to learning, and whether you can continuously set aside some time to build upon your studies.
The most effective way to learn Swift programming will depend on your learning style.
A written course may work best for app developers who prefer reading, Swift Playgrounds for developers who learn on the job, popular video tutorials on Udemy or Codecademy for listeners, or University provided video courses on Coursera for those who favour an academic setting.
Note that the perceived difficulty of a language is not nearly as important as the educational content available to the student.
C++ is perceived to be difficult, but with a comprehensive and well-written introduction, one could make quicker progress than if they attempted to learn a higher level language (such as Python) with subpar material at hand.
A wealth of resources is undoubtedly key to learning software development tools. Given the iPhone’s dominance in paid app revenue share and the incentive to learn Swift that stems from that, Swift unsurprisingly does have a wealth of educational resources available, contributed by both Apple and third parties.
Apple is aggressively pushing Swift to be learned in the classroom with a huge teaching in school initiative.
In general, higher quality material is published as a programming language matures and gains more adoption, and this is something Swift is definitely experiencing.
How long does it take to learn Swift programming?
Critically, what you do have control over are your study habits and schedule – and these disciplines will translate to the time it will take for you to become proficient in Swift programming.
With a structured schedule – whether daily, 4 times a week, or similar time frames that suit your schedule – you can learn the key Swift programming concepts in a matter of weeks and start putting them to use in production apps.
The following tips will ensure you will be successful in doing so:
- Take one exercise at a time and focus on the underlying concept until you are comfortable with it. For example, do not move onto namespaces if you are not yet comfortable with basic data types, variables, or structs.
- As you learn a new Swift feature, add that feature to your existing code. This way, you can witness first hand how adding more code can enhance your app and give it more functionality – and what changed from previous code samples to make that happen.
- Do not attempt to design a full-blown app straight away. Slowly build up your app’s capabilities in a manner similar to the previous point.
- Do not delete any of your exercise projects or sample code. Keep them as reference material or code that you can adapt to future projects as a starting point. Copying your existing code (even from tutorials and courses) and tweaking it for future projects is time-saving, but it will also reinforce why you created that code initially.
- Go at your own pace. Every developer is in a unique situation and will be attending to their own unique challenges in life on top of their app development endeavours. Measure your progress based on your own schedule, not on others’ who may have a lot more time on their hands or less life stresses to contend with.
Aid your learning process with the Swift mentorship program
Keep an eye out for the Swift Mentorship Program timelines, and apply if you are interested in having a Swift expert guide you along your learning process.
See the full details of the Swift Mentorship Program here.
Are other skills required to learn Swift?
Familiarity with Xcode will certainly help you learn Swift. Version Control is a huge focus on Xcode 13, so being able to interact with Git within Xcode will be hugely beneficial to managing your Swift projects, as well as working in a team environment.
Being able to work with device simulators and basic Terminal commands will also make for a smooth learning process.
Swift is open source, can I contribute?
Yes! Check out the official website for details on contributing to Swift.
Learning Swift Summary
Swift is Apple’s current favoured app development solution throughout their entire platform catalogue from iOS development to CarPlay support – but outside of that ecosystem Swift has made little progress.
However, Swift was designed to be general purpose and is actively maintained, so future potential use cases should not be written off completely.
Swift is beginner-friendly and requires no programming experience to get started, but the speed at which you become proficient will depend largely upon your study habits.
Thanks to the community, the mentorship program is also available, albeit for a limited number of positions. There are however a wealth of educational resources both online and in the classroom to get started with Swift, ranging from books, videos, courses with exercises and tutorials, and more.