Hacking with Swift News, tips, and tutorials from Hacking with Swift https://www.hackingwithswift.com/articles/rss (c)2020 Paul Hudson https://www.hackingwithswift.com/favicon-96x96.png Hacking with Swift https://www.hackingwithswift.com/articles/rss How to build your first SwiftUI app with Swift Playgrounds https://www.hackingwithswift.com/articles/245/build-your-first-swiftui-app-with-swift-playgrounds https://www.hackingwithswift.com/articles/245/build-your-first-swiftui-app-with-swift-playgrounds Learn the basics of SwiftUI and build a real app along the way. Wed, 15 Dec 2021 22:25:43 +0000 Swift Playgrounds lets you build a complete iOS app from scratch, right on your iPad. You get to draw upon Apple’s powerful SwiftUI framework, you can pull in libraries that other people have written, and if you want you can even move your project over to your Mac and continue it in Xcode, Apple’s full-blown code editor.

In this tutorial I’m going to walk you through building your very first app using Swift Playgrounds for iPad, where you’ll be able to show pictures of your friends and family, and tapping one of them will play a sound – it’s just for fun, but you’ll learn a lot along the way, and also make use of other built-in software on your iPad. This tutorial is aimed at beginners, so you don’t need any prior Swift experience.

To follow along you’ll need to install Playgrounds from the App Store, but that’s it – you don’t need Xcode or even a Mac. In case you were curious, I’m using Apple’s Magic Keyboard with an iPad Pro, running iOS 15.2.

First steps

To get started, press the “App” button under “Get a Playground” to create a new project. This will be called My App by default, and it will be given a random icon – I’ll show you how to change those later.

Go ahead and tap your new playground to open it for editing, and you’ll see Playgrounds splits into two parts: on the left is some simple Swift code to get us started, and on the right is a live preview that shows your actual code running.

I expect the starter code will change over time, but that’s okay because I want you to delete almost all of it – leave only this behind:

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")

As you delete parts, you’ll see the preview on the right change immediately – it really is live, and later on you’ll see it’s interactive too.

Our remaining code does several things:

  1. It tells Swift to bring in the SwiftUI fra...
Swift Playgrounds 4 is here, and it’s a thing of beauty https://www.hackingwithswift.com/articles/244/swift-playgrounds-4 https://www.hackingwithswift.com/articles/244/swift-playgrounds-4 Building complete apps on your iPad is now possible. Tue, 14 Dec 2021 16:41:59 +0000 At WWDC21 Apple revealed that Swift Playgrounds was getting a huge upgrade to allow us to build complete SwiftUI apps, including not only a live preview of our work but also the ability to ship direct to the App Store.

Well, Playgrounds 4 just arrived and I’m really pleased to say they nailed it: this is a landmark release for Swift Playgrounds, introducing instant interactive previews, lightning-fast code completion, complete integration for Swift Package Manager repositories, and so much more…

In case you’re short on time, here’s the TL;DR:

  • Yes, you can now build SwiftUI apps right on your iPad.
  • Yes, you can use also UIKit if you prefer.
  • Yes, you can ship your apps to the App Store straight from your iPad.
  • Yes, it supports Swift Package Manager packages from GitHub.
  • Yes, you get the fantastic new code completion, just like with Xcode.
  • Yes, it ships with Swift 5.5 and all the concurrency awesomeness that entails.

Okay, let's explore the app…

Building iPad apps on your iPad

Folks have been requesting Xcode for iPad for some time, but that would have required a pretty epic effort – does that mean all of Interface Builder? All the Objective-C and C++ support? Or – *cue silent screaming* – Info.plist files?

Swift Playgrounds has chosen a different way: rather than trying to recreate all of Xcode on iPadOS, it instead aims to produce “Diet Xcode” – by which I mean “slimmer, faster, and streamlined” and not “why does my drink taste weird.” That means we get Xcode-style code completion that appears instantly, we get Xcode-style instant SwiftUI previews as we type, we get Xcode-style imports for SPM packages through Git, and much more.

![Swift Playgrounds 4 showing inline code completion.](/uploads/arti...

Write better code with Swift Algorithms https://www.hackingwithswift.com/articles/243/write-better-code-with-swift-algorithms https://www.hackingwithswift.com/articles/243/write-better-code-with-swift-algorithms Write faster, simpler, safer Swift code with this powerful open-source package. Thu, 02 Dec 2021 22:55:29 +0000 Swift’s standard library is packed with types and functions to solve the most common code problems quickly and efficiently, but it doesn’t cover everything. So, for more advanced needs we need to turn to Swift Algorithms: Apple’s open source package of sequence and collection algorithms, tuned for maximum performance and flexibility.

With the 2021 Advent of Code happening right now, this is a great time to see how Swift Algorithms can help you write faster, simpler, and safer code. There’s functionality for uniquing sequences, chunking them, selecting several random elements, compacting them, and more, and most return new, highly-optimized sequence types that are more efficient than flattening everything to a simple array.

Plus, Apple has said that Swift Algorithms provides an opportunity to explore algorithmic problems and solutions before graduating them into the main standard library – you get better code today, and a look in at what the standard library might become in the future. What’s not to like?

Best of all, adding Swift Algorithms to your Xcode project takes only a few moments: go to the File menu, choose Add Packages, select Apple Swift Packages, then select “swift-algorithms” and click Add Package. Now just add import Algorithms to your code, and you’re all set!

In this article I’m going to pick out just a little of what Swift Algorithms can already do, focusing on nine particular algorithms I find most useful. Let’s get to it…

  • Prefer to watch this as a video? Here you go!

Chaining sequences

If you have two arrays of data and want to loop over them both, you might write something like this:

let names1 = ["Jane", "Elizabeth", "Mary", "Kitty"]
let names2 = ["Daphne", "Eloise", "Francesca", "Hyacinth"]

for name in names1 + names2 {

That will print all eight names, but in...

Learn essential Swift in one hour https://www.hackingwithswift.com/articles/242/learn-essential-swift-in-one-hour https://www.hackingwithswift.com/articles/242/learn-essential-swift-in-one-hour Here’s the least you need to know to get started with Swift. Fri, 15 Oct 2021 21:23:01 +0000 In this article I’m going to introduce you to the fundamentals of the Swift programming language in about one hour.

This article is aimed at two kinds of people: folks who have completed the introduction to my 100 Days of SwiftUI course and are looking for a quick review, and folks who are experienced with other languages and want to transfer their skills over to Swift.

We’re going to move fast because this is designed to be a primer – if you find yourself struggling to understand something, visit the 100 Days of SwiftUI to complete the longer, more detailed introduction there.

Let’s get to it!

Creating constants and variables

Swift can create constants and variables, but constants are generally preferable.

Use this to create then change a variable string:

var name = "Ted"
name = "Rebecca"

If you don’t want to change a value, use a constant instead:

let user = "Daphne"

The print() function is helpful for learning and debugging, and shows some information about a variable:



Swift’s strings start and end with double quotes:

let actor = "Tom Cruise"

And they work great with emoji too:

let actor = "Tom Cruise 🏃‍♂️"

If you want double quotes inside your string, place a backslash before them:

let quote = "He tapped a sign saying \"Believe\" and walked away."

If you want a string that spans multiple lines, start and end with three double quotes, like this:

let movie = """
A day in
the life of an
Apple engineer

Swift provides many useful properties and methods for strings, including .count to read how many letters it has:


There are also hasPrefix() and hasSuffix(), which lets us know whether a string starts or ends with specific letters:


Important: Strings are case-sensitive in Swift, so ...

My favorite new Swift API from iOS 15 https://www.hackingwithswift.com/articles/241/how-to-fetch-remote-data-the-easy-way-with-url-lines https://www.hackingwithswift.com/articles/241/how-to-fetch-remote-data-the-easy-way-with-url-lines AsyncSequence and effectful read-only properties combine to make something beautiful. Thu, 19 Aug 2021 13:11:29 +0000 WWDC21 came packed with lots of new features for Swift, SwiftUI, Foundation, and more, but in all the WWDC videos I’ve watched only one made me do a double take – I had to rewind and rewatch it just to make sure I hadn’t misheard.

The feature sounds simple, but makes for quite astonishing code: it’s the lines property on URL, which downloads and returns lines of text from a URL as they are fetched. Internally this builds on a huge amount of functionality, not least effectful read-only properties and AsyncSequence, and the end result is quite remarkable in terms of its simplicity.

In its simplest form this means we can access string data directly from a URL, either local or remote. This is perfect for simpler APIs that vend data line by line, such as plain-text files or CSV – Swift even keeps the connection open as long as necessary so new data can be streamed in as needed.

Trying it out with SwiftUI

Using this API, we could write a small app to fetch a collection of quotes from a server and display them in a list, all using hardly any code:

struct ContentView: View {
    @State private var quotes = [String]()

    var body: some View {
        List(quotes, id: \.self, rowContent: Text.init)
            .task {
                do {
                    let url = URL(string: "https://hws.dev/quotes.txt")!

                    for try await quote in url.lines {
                } catch {
                    // Stop adding quotes when an error is thrown

Perhaps you can see what made me do the double take in the first place – I was surprised to be able to access lines directly on a URL, rather than routin...

Hacking with Swift Live 2021 raises $61,000 for charity https://www.hackingwithswift.com/articles/240/hacking-with-swift-live-2021-raises-61000-for-charity https://www.hackingwithswift.com/articles/240/hacking-with-swift-live-2021-raises-61000-for-charity Make apps, make friends, make a difference. Thu, 05 Aug 2021 14:42:37 +0000 Hacking with Swift Live 2021 just finished, delivering three days of tutorials and workshops on all the major concurrency changes to Swift, the many improvements for SwiftUI, and more. Even better, because all our profits go to charity we were able to donate $61,000 to an incredible cause – everyone got to take their Swift skills forward, meet new friends, and make a real difference outside our community.

Just like last year, we donated all our profits to Special Effect, who help to bring joy, creativity, and confidence into the lives of people with disabilities. With the pandemic somehow still raging many charities continue to have a hard time raising funds, so we’re glad to play a part in helping continue their important work.

The feedback so far has been overwhelmingly positive, and I’m really grateful to everyone to bought a ticket, our individual sponsors, the many folks who bought diversity tickets, and of course our corporate sponsors.

This year we were lucky enough to have two platinum sponsors:

  • DuckDuckGo has a private search engine, a privacy-focused browser app, and a privacy browser extension, so I think you know exactly what their #1 priority is!
  • Instabug’s tools can help you find and fix bugs faster thanks to comprehensive crash reporting and performance metrics.

We also had three silver sponsors:

  • Backbase are building a software platform to help banks move faster in a digital-first world.
  • Emerge analyses your code to provide insights to help make your app size smaller, and even generates size diffs on every PR!
  • Bitrise offers fast, flexible, and scalable continuous integration and delivery for app developers, offering dozens of integrations with well-known tools.

Each of those sponsors went out of their way to support our event, not only making significant charity donations but al...

WWDC21: Wrap up and recommended talks https://www.hackingwithswift.com/articles/239/wwdc21-wrap-up-and-recommended-talks https://www.hackingwithswift.com/articles/239/wwdc21-wrap-up-and-recommended-talks Packed sessions, digital lounges, and a look forward to 2022. Sun, 20 Jun 2021 21:39:38 +0000 Apple’s annual event is done and dusted for another 12 months, featuring a major raft of updates for all platforms, plus Swift, SwiftUI, UIKit, and more. But perhaps just as importantly, this year also featured a number of improvements to the conference format itself, and it seems increasingly clear that we cannot go back to the old WWDC format again.

In this article I’ll go over how I thought the event went, pick out the talks I enjoyed the most and would recommend you watch, highlight some of my favorite community events, and put forward a handful of suggestions for how WWDC22 might look.

And away we code!

WWDC20 took place during a global pandemic, and WWDC21 also took place during a global pandemic. But this year Apple was prepared – perhaps they had some plans in place for an in-person WWDC just in case things had improved by the start of the year, but it seems clear this year a great deal of work had gone into making WWDC work better as an event for everyone.

Even from the very first keynote video it was obvious this year Apple had doubled down on the production quality for their videos. Yes, Craig’s teleportation effect somewhat stole the show, but also we saw carefully orchestrated presenter handovers across a wide team and a variety of impressive CGI overlays that brought the launch day to life.

A woman talking in front of the Swift logo. This is Susan Prescott, introducing a segment on developer technologies.

But the keynote did a lot to set the stage for the week. Yes, Craig called developers “the heart and soul of WWDC” – I mean, it’s right there in the name – but things really kicked off when Ted Kremenek took over presenting. I can’t imagine I was alone in feeling my pulse pick up when that happened, because Apple only shows code during the keynote when they mean business. Unsurprisingly this segment focused on concurrency, and even if you’ve only managed to watch a few of the videos from WWDC21 you’ll almost ...

How to document your project with DocC https://www.hackingwithswift.com/articles/238/how-to-document-your-project-with-docc https://www.hackingwithswift.com/articles/238/how-to-document-your-project-with-docc Markdown-powered documentation is now just a click away. Sun, 13 Jun 2021 15:22:35 +0000 DocC is Apple’s new tool for building beautiful, interactive, and native-feeling documentation right from your code, and it integrates smoothly into both Xcode and the web.

In this article I’m going to walk you through the fundamentals of using it in two different ways: building documentation for a framework, and adding articles that provide more depth. Along the way, you’ll see some places where DocC works brilliantly, and also some places where it doesn’t really work like I’d expect at all. And that’s okay – it’s only the initial release, after all.

Before I start, though, there are some basics:

  • You need to have Xcode 13 installed in order to have access to DocC.
  • It supports only Swift at this time. They have already received requests to add Objective-C support, and in the long term I hope they’ll add support for other languages too.
  • In case you were curious, DocC is short for “Documentation Compiler”, and it’s pronounced with two equally stressed syllables – “Doc-See” as opposed to “doxy”.
  • Xcode is packed with lots of major new features – it’s another real stand out year, and I hope the team are feeling really proud. You can find out more in my article What’s new in Xcode 13.

Please keep in mind I’m using Xcode 13 beta 1, so it’s all early days at this point – I expect DocC to get polished up a lot before the final release later this year.

First, what DoC is not

The first thing I did when trying out DocC is what I expect most app developers would do: I opened up one of my projects to see what DocC would make of it. In my case, that was Unwrap – it’s a good size of project with various dependencies, and matches the kind of thing many app developers will be working with.

If you want to try this in your own app project, just go to the Product menu and choose Build Documentation. It might take a minute or two to ...

The Complete Guide to SF Symbols https://www.hackingwithswift.com/articles/237/complete-guide-to-sf-symbols https://www.hackingwithswift.com/articles/237/complete-guide-to-sf-symbols Example code, tips, and techniques for both SwiftUI and UIKit Sun, 13 Jun 2021 08:06:10 +0000 SF Symbols allows us to render a huge and growing variety of icons inside our apps, and every year it gets bigger – not only do many more icons get added, but iOS 14 added the ability to render multicolor icons and iOS 15 added the ability to have complete control over individual layers.

In this article I’m going to walk you how to use SF Symbols in your projects, providing code for both SwiftUI and UIKit. Let’s get into it…

Tip: The best way to browse the list of symbols is using Apple’s free SF Symbols app.

How to load an SF Symbol

The simplest thing you’re going to want to do is load a symbol. We’ll be using “star” here, but if you’re using the SF Symbols app you can right-click any symbol and choose Copy Name.

In SwiftUI loading an image is done by placing an Image into your view hierarchy using its systemName initializer:

Image(systemName: "star")

In UIKit you need to use UIImage then place it in a UIImageView, like this:

let image = UIImage(systemName: "star")
let imageView = UIImageView(image: image)

How to place SF Symbols next to text

SF Symbols work great when used inside text, particularly when they contain common symbols such as error crosses, check marks, calendars, and similar.

In SwiftUI placing an image next to text is done like this:

Label("Please try again", systemImage: "xmark.circle")

If you want to place it inside the text string, it’s better to use string interpolation with Image, like this:

Text("Please press the \(Image(systemName: "calendar")) button")

For UIKit the code is a little more complex because you need to use NSAttributedString and NSTextAttachment to render something into a UILabel, but the same code lets you place the images wherever you want them:

let attachment = NSTextAttachment()
attachment.image = UIImage(systemName: "xmark.circle")

let imageString = NSMutableAttributedString(attachment: attach...
What’s new in Xcode 13? https://www.hackingwithswift.com/articles/236/whats-new-in-xcode-13 https://www.hackingwithswift.com/articles/236/whats-new-in-xcode-13 Vim keybindings, integrated collaboration, faster version comparison, and more. Thu, 10 Jun 2021 20:22:54 +0000 Xcode 13 arrived at WWDC21 and includes a huge range of new features, improvements, and performance enhancements. In this article I’m going to walk you through all the key changes, so you can get up to speed quickly, but before I start I need to make two things clear:

First, no, I don’t have beta access to Xcode Cloud or the new Swift Playgrounds. Trust me, I wish I did! Both of these things look likely to be significant upgrades for the Swift community, and I’m really keen to try them out at the earliest opportunity.

And second, you might immediately note that Xcode hides your file extensions by default in the project navigator. This seems to mimic your Finder configuration, so if you’re suddenly confused where your file extensions have gone then you can bring them back With This One Weird Tip: go to Xcode’s preferences, select General, then change File Extensions to Show All. I’m going to try sticking with hidden extensions to see how I get on with it.

Anyway, in this article I’ll be talking about the new workflow tools for teams, the new source control features, the new improvements to how we write code, and more – it’s a packed release, so let’s get straight to it.

Source editor improvements

First let’s talk about the source editor, which is where we spend most of our time – this is just the way we type code into Xcode, as opposed to all the main IDE features around it.

When I posted about some of these on Twitter, a bunch of folks replied back saying how Xcode sucks because their personal favorite IDE had these features years ago, and honestly just please pass me by with those kinds of comments – if I wanted to use your IDE I would already be doing so.

So, let’s talk about some major changes to the way we write code in Xcode.

First, if you use a type that isn’t currently available, Xcode can automatically import it for you. So, if you write code like this:

struct ExampleView: View

…then Xcode will...

What’s new in SwiftUI for iOS 15 https://www.hackingwithswift.com/articles/235/whats-new-in-swiftui-for-ios-15 https://www.hackingwithswift.com/articles/235/whats-new-in-swiftui-for-ios-15 Visual effects, remote URLs, and cleaned up APIs galore. Tue, 08 Jun 2021 06:52:24 +0000 Expectations were always going to be high for SwiftUI this year, but the team didn’t disappoint – they’ve shipped a massive collection of improvements and features, including a new AsyncImage view for loading remote images, swipe actions for list rows, pull to refresh, plus shorter, simpler APIs for common uses. Alongside huge improvements to Swift itself (see What's new in Swift 5.5 for more on that), this is another significant leap forward for SwiftUI and I’m really keen to dive in.

Please keep in mind that these changes are very new – I'm pushing it as hard as I can, experimenting, refining, sharing, and learning all at the same time. If you have any feedback, please tweet me @twostraws.

You can watch the video below, or scroll down for links to articles.

The big stuff

More welcome improvements

Hacking with Swift+ turns 1! https://www.hackingwithswift.com/articles/234/hacking-with-swift-plus-turns-1 https://www.hackingwithswift.com/articles/234/hacking-with-swift-plus-turns-1 New features include ad-free browsing, online books, and more. Tue, 01 Jun 2021 22:21:42 +0000 One year ago today I launched Hacking with Swift+, and already I’ve released over 130 articles and videos covering advanced Swift, SwiftUI, special effects, algorithms, and so much more – it’s been incredible, and I’m really grateful for everyone who subscribed. But I’m not resting on my laurels.

Six months ago I announced that everyone who subscribed for at least a year would get exclusive free gifts mailed to them wherever they lived in the world, and three months ago I added all the videos from Hacking with Swift Live 2020 as another bonus.

Today I’m really pleased to reveal the next set of enhancements:

  • All Hacking with Swift+ subscribers can now browse the whole site with no advertising – that means no sponsor text in the page, no fixed gray bar along the top of articles, and no “buy our books” sidebar on the right. Instead, every page on the site is wider and more streamlined for an optimized reading experience.
  • There’s a new private forum exclusively for Hacking with Swift+ subscribers to ask question questions and chat.
  • I’ve started the process of adding chapter markers to all the Hacking with Swift+ videos. This will take some time to complete, but work has already begun.
  • All Hacking with Swift+ subscribers can enjoy a 20% discount on the download editions of my books and bundles, available year round.

All that is on top of the existing benefits of subscribing.

But we can do better!

I’ve seen some other sites offer enhanced subscriptions that include online access to their books, charging a lot more for the privilege.

That isn’t how I work.

I realized some time ago that as long as I was making enough money to be happy, I didn’t need to earn more – that’s part of the reason I run so many charity events, give away books to folks who need them, and publish so much free content.

So I set out to make a Hacking with Swift+ subscription that gave folks my books to read online without having to break the bank. Obv...

What's new in Swift 5.5? https://www.hackingwithswift.com/articles/233/whats-new-in-swift-5-5 https://www.hackingwithswift.com/articles/233/whats-new-in-swift-5-5 Async/await, actors, throwing properties, and more! Fri, 28 May 2021 11:49:34 +0000 Swift 5.5 comes with a massive set of improvements – async/await, actors, throwing properties, and many more. For the first time it’s probably easier to ask “what isn’t new in Swift 5.5” because so much is changing.

In this article I’m going to walk through each of the changes with code samples, so you can see how each of them work in practice. This is the first time so many huge Swift Evolution proposals has been so tightly interlinked, so although I’ve tried to organize these changes in a cohesive flow some parts of the concurrency work only really make sense once you’ve read through several proposals.


SE-0296 introduces asynchronous (async) functions into Swift, allowing us to run complex asynchronous code almost is if it were synchronous. This is done in two steps: marking async functions with the new async keyword, then calling them using the await keyword, similar to other languages such as C# and JavaScript.

To see how async/await helps the language, it’s helpful to look at how we solved the same problem previously. Completion handlers are commonly used in Swift code to allow us to send back values after a function returns, but they had tricky syntax as you’ll see.

For example, if we wanted to write code that fetched 100,000 weather records from a server, processes them to calculate the average temperature over time, then uploaded the resulting average back to a server, we might have written this:

func fetchWeatherHistory(completion: @escaping ([Double]) -> Void) {
    // Complex networking code here; we'll just send back 100,000 random temperatures
    DispatchQueue.global().async {
        let results = (1...100_000).map { _ in Double.random(in...
Reimagining Hacking with Swift https://www.hackingwithswift.com/articles/232/reimagining-hacking-with-swift https://www.hackingwithswift.com/articles/232/reimagining-hacking-with-swift With your help things can get better. Fri, 07 May 2021 14:54:05 +0000 Yesterday I wrote a long article called Reimagining Apple’s documentation, in which I wrote down a variety of ways I'd love to see Apple's developer documentation evolve and improve in the future. Although it was written with nothing but appreciation in mind, the article was effectively me telling other people how to do their job – other people, let's not forget, who are already working very hard to deliver the best they can for us.

Anyway, in that article I said, “I need to acknowledge that there are a whole bunch of ways I could make my own site better,” before launching off into a long rant about Apple's site. Well, let’s focus on Hacking with Swift, because if I’m going to look at Apple’s documentation output in the cold light of day I should do the same for my own site.

Where my work is today

Hacking with Swift is visited by over 700,000 unique visitors every month, serving up over 5,000,000 page views – all at the same time as me running a YouTube channel with almost 60,000 subscribers, writing a newsletter with almost 40,000 readers, and delivering talks at conferences. Every single day people get in touch to thank me for an article or video, to ask questions, to suggest new topics, and more, and I’ve lost track of how many people have said they got a job thanks to my work.

I also work hard to make sure I use what platform I have to help people outside our community too, whether that’s through Swift for Good raising money for Black Girls Code, Hacking with Swift Live raising money for Special Effect, my SwiftUI birthday livestream raising money for folks who are sleeping rough, my iOS Accelerator workshop raising money for my kids’ school, or other efforts.

Honestly, that’s great. It’...

Reimagining Apple’s documentation https://www.hackingwithswift.com/articles/231/reimagining-apples-documentation https://www.hackingwithswift.com/articles/231/reimagining-apples-documentation Example code, faster navigation, and goodbye to No Overview Available. Thu, 06 May 2021 16:11:40 +0000 For a number of years my #1 WWDC wish was that Apple would do something to dramatically rethink its approach to developer documentation. I still hope WWDC21 will be The Year When Something Big Happens To Apple’s Documentation, but rather than just wave vaguely and say “I want better docs” I figured I’d write down some specific thoughts that have been rattling around in my head.

I have a simple mental metaphor for what I want, which is this: what would happen if the hardware team who designed iPhones and iPads were asked to build developer documentation?

I don’t mean “make them describe thousands of APIs,” but instead I mean their mentality – the primary reason most of us buy so many Apple devices is because they are loved down to the micron level. Every tiny part of my iPhone, my iPad, my Apple Watch, and more has been thought about and made as good as they can possibly make it, from the screen, to the audio, to the battery, and beyond. The result is that the finished devices just feel fantastic even many years after they were released.

So I use that as my yardstick: what would magical documentation look like?

I’m going to outline my answers below, but honestly the conclusions won’t surprise anyone: getting fantastic, world-leading developer documentation isn’t about fancy new approaches to tutorials or interactive experiences, but almost entirely about finding the fastest, simplest ways to solve developer problems effectively.


Short on time? Fine – here’s the bulleted list of what I wish would change:

  • The top 500 most popular APIs (measured by page views) should have example code attached, ideally several examples with headers clearly marking what problem is being solved.
  • The top 100 most popular APIs should get either a screenshot or a video showing exactly how it works and what the result is.
  • Any place where header files have documentation comments and their matching online documentation is “No overview available” should have the hea...
How to Become an iOS Developer in 2021 https://www.hackingwithswift.com/articles/230/how-to-become-an-ios-developer https://www.hackingwithswift.com/articles/230/how-to-become-an-ios-developer The skills, resources, and networking that will get you to your goal Wed, 31 Mar 2021 20:37:46 +0000 In this article I want to walk you through what I think it takes to become an iOS developer in 2021. I’m aiming this squarely at two groups of people: absolute beginners to Swift – folks who have never built anything for iOS before – and also so-called false beginners, who are folks who might have tried to learn Swift before but never really reached their goal of getting a full-time job.

Regardless of what level you are right now, the goal here is the same: getting you in the right position to apply for a junior iOS developer role at a company.

We’re going to look at the skills you should be learning, the courses you can take, how to get connected to the community, common mistakes folks make, and more, and best of all everything I’ll talk about will be completely free so you won’t need a penny to follow along.

Seriously, too many people think spending a ton of money is the fast track to reaching their dream job, when really the most important things are determination and willpower. And here’s a hint for you: if you’re already thinking you want to skip ahead in this article, maybe you should consider working on your willpower!

There are 7 sections to this article:

  1. Core skills you absolutely need to know to get a job.
  2. Extension skills that are nice to have – the ones that will set you apart from the pack, if you have the time to learn them
  3. Common mistakes people make when they are trying to learn.
  4. Resources you can use to learn Swift that are completely free.
  5. How you can connect to the iOS development community.
  6. An idea of how long it will take to reach your goal.
  7. Preparing to apply for your first job
  • This article is also available as a video if you prefer. The content is the same, so use whichever is easiest for you.

What are the core skills you need to be an iOS developer?

What is the absolute minimum set of skills you need to get a job in iOS development? I think there are five things in total:

  1. S...
24 Quick Xcode Tips https://www.hackingwithswift.com/articles/229/24-quick-xcode-tips https://www.hackingwithswift.com/articles/229/24-quick-xcode-tips Write code faster, build better tests, and navigate around projects more efficiently. Fri, 12 Feb 2021 22:02:25 +0000 Xcode is a huge program, and if you can learn one or two new tips that help you work more effectively you can save hours of time every week.

In this article I want to walk you through 24 quick Xcode tips that help you write code faster, build better tests, and navigate around large projects more efficiently – there’s something for everyone!

  • This article is also available as a video if you prefer. The content is the same, so use whichever is easiest for you.

1. Generating class initializers

Swift can synthesize memberwise initializers for structs, but not for classes. Fortunately, Xcode can generate the code for us: select your class name, then go to the Editor menu and choose Refactor > Generate Memberwise Initializer. Done!

2. Environment overrides

When building software, it’s important to make sure your app works for everyone. One great way to do that is with Xcode’s environment overrides panel, which lets you adjust Dynamic Type size, accessibility options, and appearance all in one place.

3. Selecting blocks of code

You probably already know that you can click after any open { or close } brace to have Xcode highlight its matching brace, but another useful tip is that you can double click a brace to select the entire block of code it contains.

4. Checking our spelling

Xcode can check if your spelling is correct, and it even understands that camelCaseNames should be treated as separate words. Go to the Edit menu and choose Format > Spelling and Grammar > Check Spelling While Typing, and Xcode will check your code for typos.

5. Fixing all issues

If you have a Swift file with many errors, you can use Xcode’s fix-its to try to correct them one by one. But a faster way is to go to the Editor menu and choose Fix All Issues to apply fix-its all at once. (Make sure and double-check which changes were made!)

6. Deleting search results

When you search using Xcode’s find navigator, you can click to v...

What’s new in Swift 5.4? https://www.hackingwithswift.com/articles/228/whats-new-in-swift-5-4 https://www.hackingwithswift.com/articles/228/whats-new-in-swift-5-4 Multiple variadic parameters, improved implicit member syntax, result builders, and more! Tue, 02 Feb 2021 15:35:14 +0000 Swift 5.4 brings with it some huge compilation improvements, including better code completion in expressions with errors and big speed ups for incremental compilation. However, it also adds some important new features and refinements, so let’s dig into them here…

Improved implicit member syntax

SE-0287 improves Swift’s ability to use implicit member expressions, so rather than just having support for exactly one single static member you can make chains of them.

Swift has always had the ability to use implicit member syntax for simple expressions, for example if you wanted to color some text in SwiftUI you could use .red rather than Color.red:

struct ContentView1: View {
    var body: some View {
        Text("You're not my supervisor!")

Prior to Swift 5.4 this did not work with more complex expressions. For example, if you wanted your red color to be slightly transparent you would need to write this:

struct ContentView2: View {
    var body: some View {
        Text("You're not my supervisor!")

From Swift 5.4 onwards the compiler is able to understand multiple chained members, meaning that the Color type can be inferred:

struct ContentView3: View {
    var body: some View {
        Text("You're not my supervisor!")

Multiple variadic parameters in functions

SE-0284 introduced the ability to have functions, subscripts, and initializers use multiple variadic paramete...

Which SwiftUI property wrapper to choose in any situation https://www.hackingwithswift.com/articles/227/which-swiftui-property-wrapper https://www.hackingwithswift.com/articles/227/which-swiftui-property-wrapper Decide which property wrapper is the right choice for your needs. Wed, 27 Jan 2021 17:51:44 +0000 SwiftUI uses property wrappers to understand how we create and store data in our views, but if you need helping choosing which property wrapper is right for you I've made a tool to help. To find the right property wrapper for you, answer the questions below 🚀

1. Are you storing a struct, an enum, or a class?

I want to store a struct or an enum.

2. Will the value change over time?

Yes, it will change as my app runs.

3. Are you creating the value in your view, or will it be passed in from somewhere else?

I'll be creating the value locally in my view.

4. Is the property being used to track some sort of user input?

Yes, this is will track an active gesture.

You should use the @GestureState property wrapper, like this:

@GestureState private var dragAmount = CGSize.zero

Although you could also use @State for this purpose, @GestureState is significantly more efficient.

You can learn more about the @GestureState property wrapper here: What is the @GestureState property wrapper?

Yes, this will track which view has keyboard focus.

You should use the @FocusState property wrapper, like this:

@FocusState private var isUsernameFocused: Bool
...]]> 5 Steps to Better SwiftUI Views https://www.hackingwithswift.com/articles/226/5-steps-to-better-swiftui-views https://www.hackingwithswift.com/articles/226/5-steps-to-better-swiftui-views Learn to make your SwiftUI views smaller, simpler, and more reusable. Wed, 27 Jan 2021 11:57:00 +0000 As SwiftUI projects grow more complex, it’s common to find your views get larger and larger as you cram more functionality into them. In this article I’ll walk you through the underlying problem, and demonstrate five steps you can take to make your views simpler, smaller, and smarter – all demonstrated using a real SwiftUI project, so you have actual code to follow along.

You can get the project source code, including both before and after versions, from this link.

  • This article is also available as a video if you prefer. The content is the same, so use whichever is easiest for you.

Still here? Okay, let’s get to it…

What’s the problem?

This is a really challenging time for SwiftUI because at this point we’re kind of past the novelty of SwiftUI itself – we’re used to the idea that we can build user interfaces really fast, we’re used to the idea of tracking state effectively, and we’re used to the idea that we can write layouts that work great on all of Apple’s platforms.

However, although many people are already comfortable with the way SwiftUI works, we are still quite a long way from agreeing best practices. For example, if you have several different ways of solving a problem, we’re still in the process of figuring out which one makes most sense for a given situation.

So, we’re at this strange position where many people are learning SwiftUI and writing lots of it, but the apps we build are growing in size and complexity and as a result are starting to suffer from very similar problems that we faced in UIKit in the early years.

Previously it was common to tackle the long-standing UIKit curse of Massive View Controllers, but in SwiftUI we don’t have view controllers at all – in fact, many would say that the lack of view controllers is the best feature of SwiftUI!

However, we do make a lot of view structs where we cram a lot of functionality. This created a wholl...