BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Swift Playgrounds 4 is here, and it’s a thing of beauty

Building complete apps on your iPad is now possible.

Paul Hudson       @twostraws

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…

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

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.

And don’t think for a moment there are compromises on what you can code, because there really aren’t: this is full Swift 5.5 with all the latest concurrency features, plus access to the full set of SwiftUI API for iOS 15. Even better, at last there is access to debug output using print() and similar – by default it slides up from the bottom in a toast-style notification then animates away after a few seconds, but you can also make the console permanently visible if you prefer.

But, critically we don’t get some of Xcode’s biggest problems. For example, when you want to add a capability to a Swift Playgrounds app, it’s all done using a beautiful new user interface where you select from a list, then enter any addition data as prompted – that means goodbye to adding keys like “NSLocationAlwaysAndWhenInUseUsageDescription” to your property list.

Swift Playgrounds 4 showing an easy UI to add app capabilities.

Best of all, if you decide you want to move your project over from Swift Playgrounds to Xcode, you can do just that: just hit Share, then AirDrop it to your Mac, and Xcode will pick up exactly where you left off.

Fast editing, fast previewing

The first thing that hits you with Playgrounds 4 is just how fast the editor is. Just like with Xcode on the new M1 MacBook Pros, SwiftUI previews are instant on your iPad, so as you type the UI changes right in front of you. Plus, it’s always interactive, so you can swipe around, tap, and otherwise interact with your layouts as you write the code.

I’ve been using a 12.9-inch 2020 iPad Pro with the Magic Keyboard, which means I’m using the older A12Z that’s almost identical to the A12X used in the 2018 iPad Pro models. Not only does that mean a wide range of iPad devices will get the same super-fast coding experience I had, but also that folks lucky enough to have the 2021 M1-powered model are likely to see another 50% performance improvement here too. If my 2020 model is lightning fast, what would that make the M1 – scorchingly fast? Screamingly fast? Words fail me, but you can be darn sure I’m buying whatever iPad Pro Apple announces next.

Swift Playgrounds 4 showing my project structure, code, and preview side by side.

As for the Magic Keyboard, it works exactly as you’d expect and makes using Playgrounds 4 much more like working with Xcode. The keys aren’t quite the same as Xcode, though, so be prepared for a few small mental speed bumps along the way – things like selecting code and pressing Tab will delete your code and replace it with a tab rather than indenting it, or pressing Cmd+Shift+Left selects to the start of the whole line rather than the start of the code on the line like Xcode does, again meaning I often delete code by accident.

This feels a bit like the uncanny valley of coding: when Playgrounds looked and worked nothing like Xcode no one thought twice when text editing behaved different too, but now things are a lot closer – and the range of things you can build has expanded dramatically – these little difference stick out much more.

For folks who prefer a slightly more visual approach to coding, Playgrounds 4’s library lets you insert not only the full range of SwiftUI views and modifiers, but also all the built-in dynamic and semantic colors, and also the full set of SF Symbols. As much as I love Apple’s SF Symbols app for macOS, having those symbols baked right into Playgrounds is very welcome.

What moves Swift Playgrounds over from brilliant to sublime is the ability to import third-party Swift packages using Git. This is almost as simple as it is in Xcode: just enter the URL to a Git repository such as GitHub, select which version rules you want to use (e.g. “Up to next major”), then just go ahead and start using it. What you can’t do is adjust the package later – to update it to a newer version, or adjust which version you want to use. I also miss Xcode 13’s one-click support for Apple’s Swift packages, including Algorithms, Argument Parser, and Collections, but that’s hopefully a small addition for a future release.

Swift Playgrounds 4 showing SPM package import from GitHub.

When you’re done building, you’re a single button press away from launching your app full screen. There’s a slightly intrusive animation as iPad switches from the editor to playback mode, but once you’re live your app really does take up the full screen – you get a small notification at the top offering buttons to stop and restart your app, or to show the console with debug output, but that shrinks away into a tiny orange Swift icon in the status bar so your app looks and works like a regular app. (The orange Swift icon is low key one of my favorite features – a really smart solution to letting us jump into developer mode without being intrusive.)

And yes, when you’re done previewing you really can ship your app off to App Store Connect: you can add your developer account to the app, set a version number, add an icon using one of the built-in designs or a custom one, then upload the finished binary.

Would I use it to ship an app? I’m not sure. Yes, it makes it easier for everyone to ship apps to the App Store, not least because it removes the need to buy a Mac to get your app out there, but it also has some compromises along the way.

For example, you can import custom images into your app, but there are no customization options. This means if I bring in a photo from my camera roll, it comes in at the original size of 4000x3000, and I have no options to adjust that or to provide @2x or @3x assets. App Store Connect could well provide some kind of app thinning here, but it’s hard to see how that would work without any knowledge of how big each asset needs to be. Yes, we can use an external app to adjust the size downwards, but that still leaves missing support for varying screen scales, and ultimately it makes the “Import from Photos” option somewhat pointless.

I’m also not sure how Swift Playgrounds apps will work on iPhone – there are no options to control which devices our apps support, and no ability to preview the app in various virtual iPhones, so I’d feel uncomfortable shipping an app without first moving it over to Xcode and running it through various simulators. As a bonus, this also allows you to try out various Dynamic Type variations and other accessibility adjustments, which are also missing from Swift Playgrounds.

Where next?

Swift Playgrounds 4 is already a huge leap forward for Swift developers, and the new IDE features introduced backed up by the astonishing speed and the full power of Swift 5.5 make for a slick combination that will undoubtedly impress.

Yes, it opens up a huge range of opportunities for new developers to come onboard, and I am genuinely excited to see what they do with it. You really can go from a blank template to a shipping App Store app right on your iPad, and in combination with the vast array of other popular iPadOS apps this takes a huge step towards democratizing app development so that everyone really can code.

However, it also makes the iPad into a compelling environment for developers: the new Xcode-style code completion makes you feel immediately at home, and the native support for SPM, the ability to transfer your project to and from Xcode, and access to the full set of Apple frameworks like Core Motion, Core ML, ARKit, and more all combine to make this a powerhouse for more experienced app developers. I feel confident saying that if you were on the fence about getting a Magic Keyboard or similar, I think Swift Playgrounds will convert you!

So there’s no doubt about it: Swift Playgrounds 4 is exactly what Apple promised, and I’m really happy with it.

But…

(Sorry.)

There are still things I’d like to see improved. These feel small because honestly they are like rounding errors compared to the success of getting this whole new system built in the first place, but at the same time I’m hopeful that future releases will address them.

First, there is no support for storing your own projects on Git, which means you’ll need to rely on something like Working Copy to handle your version control. That’s not a problem – like I said, you’re already going to use other apps alongside Swift Playgrounds for things like images and audio – but it does mean there’s an extra little hassle for working with Git, and you don’t get little touches like inline markers for changed lines.

Second, after you’ve built a few apps you start to really miss the ability to press something like "Add to Home Screen" to get the app icon right alongside my other apps, similar to how Shortcuts works. I’m not suggesting that Apple allows standalone app device deployment straight from Playgrounds, but it would be great to have an icon that effectively launched Swift Playgrounds straight into the app.

Third, I’d love to see Apple think about how this new streamlined development process could follow through into TestFlight. I feel certain that Swift Playgrounds 4 is going to be a hit with students and teachers, but unless you don’t mind giving away your code there is no easy approach to sharing your apps with friends. This might skirt a little too close to side loading, but I’m hopeful Apple can find a middle ground that makes TestFlight sharing just a few taps.

Fourth, while I’m certainly not keen to see Playgrounds move too close to the complexity of Xcode, I would like to see a few smaller features brought across: the new Xcode 13 improvements for code completion, the ability to search for text inside a file rather than across the whole project, the ability to target specific versions of iOS and/or device types, and a starter app template suitable for UIKit development would all be most welcome.

And finally, perhaps most pressingly given what I do every day, I still don’t think Swift Playgrounds reaches the full potential of a tool teaching Swift and SwiftUI. Playgrounds 4 introduces a whole batch of new playground templates that demonstrate various techniques such as using ObservableObject, importing images, managing navigation, and more, but all they do is show the code – they point at an observable object being used in a larger project, and add a sentence or two of explainer text above.

Given the significant resources available to Apple to design, build, document, translate, and test these things, I really had hoped for something more, specifically to bridge the gap between their beautiful but limited Learn to Code playgrounds and something (relatively) more advanced like my own 100 Days of SwiftUI. As things stand, I don’t know who these new walkthroughs are aimed at, nor who would benefit from them.

Again, all of those points take little away from the resounding success that is Playgrounds 4. Yes, there are ways it can be better, but who cares – Everyone Can Code just took a gigantic step forward, and with iPads starting at just $329 there has never been a more effective way for anyone to get into app development.

One last thing to think about: how the heck will all these new features translate to Swift Playgrounds for Mac? It got an upgrade today to support Swift 5.5, but it doesn't support the new app packages built using Swift Playgrounds for iPad. It bends my brain to think about how all this app building functionality fits into Catalyst or native SwiftUI, and whether the apps we build target the desktop alongside mobile devices.

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

About the author

Paul Hudson is the creator of Hacking with Swift, the most comprehensive series of Swift books in the world. He's also the editor of Swift Developer News, the maintainer of the Swift Knowledge Base, and a speaker at Swift events around the world. If you're curious you can learn more here.

Was this page useful? Let us know!

Average rating: 5.0/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.