Swift is the newest language available for developing apps for Apple products — all of them! Though Swift is synonymous with iOS and iPhones, one of the exciting reasons to learn it is that you can also use this language to code for Macbook, iPad, Apple TV, and Apple Watch.
Chris Lattner started developing the foundations of Swift during his Ph.D. studies at the University of Illinois in 2010. After his Ph.D., while working at Apple, he gradually rallied support and funding for the new language.
Only a few people knew about the language in 2010, but collaborators were making significant contributions by 2011, and “[i]t became a major focus for the Apple Developer Tools group in July 2013,” says Lattner.
In 2014, Apple revealed Swift beta at their annual Worldwide Developer Conference (WWDC).
Before Swift, Apple products relied on Objective-C, a difficult language developed in the 1980s.
Apple introduced Swift to make it easier for people to write software for Apple devices. Swift is a simpler language with lots of new features that help coders identify errors and prevent issues that would slow down the programs we build. Many applications still use Objective-C, though. You can use both of these languages in the same application. Apple designed them to coexist.
Do I need to learn Swift?
We combed through more than 30 developer recommendations all over the web. Here are the pros and cons we found to learning Swift as a beginner coder.
- It’s more concise than Objective-C, meaning you can type fewer characters to achieve the same results. For example, when Lyft rewrote its app in Swift, developers reduced the program’s length from 75,000 lines to 22,000 lines, says Keith Smiley, an iOS engineer at Lyft. As a beginner, this means you can write faster, but more importantly, you can debug faster. It’s completely normal to spend hours trying to locate one error in one line of code in any language. When there’s an option to use a more concise language, that can reduce errors and debugging time. Huge win.
- It looks very similar to English, with minimal “technical formatting” (fewer semicolons, etc.). So if you’re a new programmer, it means it’s a lot less intimidating.
- You can learn the language using iPad games that gradually introduce general programming concepts and let you use autocomplete or drag-and-drop interactions to write short chunks of code.
- With the latest educational games on iPad, you can use Swift to control robots and drones — in real life!
- Apple is still improving Swift. With multiple new versions since 2014 (the latest is version 4), beginners can rest assured that Swift is likely to stick around for a while. Learning now is a good use of your time.
- Some developers predict that Swift will completely replace Objective-C in the next 5-7 years.
- Swift is being used for an increasing number of purposes outside of Apple’s devices and products, too. In 2015, Apple made Swift an “open source” language, meaning that anyone can see how the language works, suggest changes, and use the source code to build more products for non-Apple devices. For example, IBM released their IBM Swift Sandbox. This tool works in your browser. It shows a live preview of your code, instantly, without any of the hassle of setting up Xcode or learning how it works.
- With every new version of Swift, your app’s code may require updates, and developers warn that this can be time-consuming, as you may need to rewrite code manually.
- Xcode is the program where developers write and test Swift applications, and it’s a little buggy with Swift. For example, the autocomplete feature works better with Objective-C, and autocomplete is really helpful when you’re still getting used to new coding terms and punctuation.
- Objective-C has been the language of choice for decades, and lots of software still uses it, including much of Apple’s own software. You’ll likely need to know Objective-C if you’re planning a career in iPhone-related app development.
- Some developers prefer Objective-C simply because that’s what they learned first, and their teams don’t have time to learn a new language or convert massive programs to Swift. So if you’re planning on joining an iOS team anytime soon, chances are you’ll need to learn their preferred language.
- Objective-C compiles faster than Swift. Compiling is the step that converts your human-readable code into something the computer understands so it can package up your app and let you run it. The duration of this step isn’t likely to affect you when you’re building your first, smallish To Do app, but in the workplace, you may be working on large programs that take longer. In that case, your colleagues will likely prefer to work with Objective-C, which means you’ll be using it too.
- Because Swift is relatively new, there are fewer places where you can search for clues when you’re stuck. There are fewer Swift articles on StackOverflow, for example. There are approximately 170,000 posts about Swift and 280,000 about Objective-C. However, this landscape is changing as Swift gains popularity.
What are developers saying?
We scanned the web for a cross-section of viewpoints. The folks we’ve quoted include individual developers engaging in public discussions. There’s also a more journalistic take (ArsTechnica). And last but not least, we added the views of a coding teacher who knows what students go through as they learn Objective-C and Swift.
– Compared to Objective-C, Swift is “Easier to learn and teach, harder to mess up” – ArsTechnica
– “I am an iOS developer and working with Objective-C. But now we are migrating our project into Swift. So it’s better to learn Swift rather than Obj-C.” – Ashwini Bankar, Senior iOS Developer at TechnoPurple
– “I recommend a Swift first approach for both absolute beginners or those from different development domains.” – Pasan Premaratne, iOS Developer, Instructor in Objective-C & Swift at Treehouse
Example — What does Swift look like?
In programming tutorials, often the first lesson is a “Hello World” exercise. The goal: write a short program that tells the computer to display “Hello World” on the screen. Written in Swift, we can achieve this in one line, like this:
The same program in Objective-C looks like more complex, like this:
And this is the learning environment in Swift Playgrounds:
Next Steps — Learn Swift
If you’re eager to make apps, you’ll need a few things:
- Access to a Mac computer.
- Xcode, Apple’s free program for coding, compiling, and testing in Swift and Objective-C.
- Access to an iPhone for testing your iPhone app. You can test using simulators, but you’ll get more realistic results and fewer glitches on an a real, physical Apple device.
- Access to any other Apple device your brand new app will run on (i.e. iPad, Apple Watch, or Apple TV).
If you’re new to programming in general, the best place to start in Swift is:
– Swift Playgrounds – a colorful iPad game, no computer or Xcode required
Some of the best tutorials:
– Ray Wenderlich’s Swift Resources – Ray’s guides are among the most popular and trusted in the industry, mentioned in may top-10 lists by Apple developers. His style is friendly and approachable, often including cartoons. His free content is diverse and thorough. It includes blog-style programming essentials for those who have never done any coding. He also has loads of videos, cheat sheets, a podcast, newsletters, and books.
– Lynda.com – Often available for free with a public library membership, Lynda is popular because it’s accessible while also polished. Their courses range from novice to intermediate, broken into modules averaging 1 to 3 hours in length, with some project-based tutorials, e.g. “Build an iOS Messaging Application”. New courses are added regularly, keeping pace with Apple’s updates to Swift and iPhone features.
– Apple’s “Start Developing iOS Apps” Guide – Apple’s own guide to mobile development is spartan but very clear, with no distracting ads or gimmicks. The guide has an obvious flow, so it’s easy to see the structure of an app and how its many parts work together. Some knowledge of basic programming terminology would help, though they do include a built-in glossary of definitions relevant to the mobile app development context.
Want to hear about what it’s like to develop mobile apps with Swift? Check out CodeNewbie’s interview with mobile developer Alicia Carr.