Previous versions of Swift Playgrounds had been exclusively focused on education, with pre-defined, heavily constrained lessons. Although the previous content was excellent, it failed to provide a path from “basic programming concepts” to building an actual app. For example, the jump from Swift Playgrounds to Xcode is significant, also requiring the developer to have access to a Mac.
With Swift Playgrounds 4, Apple has (for the first time) delivered a development environment that can officially build and submit an app to the Apple App Store without the use of Xcode.
Key new features include:
- Swift 5.5, introduced language capabilities for concurrency.
- Focuses on SwiftUI apps, but also supports UIKit.
- With an Apple Developer Account, developers can submit apps to the App Store.
- Supports Swift Package Manager, including import from GitHub.
- Includes code completion, similar to Xcode.
As the name suggests, SwiftUI delivers a set of tools and APIs for user interface development, including key features such as GPU acceleration, accessibility options, retina support, widgets, etc. In short, it allows developers to build consistent, great-looking apps across all Apple platforms using Swift.
With this in mind, Swift Playgrounds 4 is still limited regarding the types of apps you can create. For example, it would be difficult to build the next “blockbuster” game. With that said, building on its heritage as an education tool, SwiftUI is a logical next step for Swift Playgrounds, opening the door to new experiences, whilst ensuring an appropriate learning curve.
I had previously used Swift Playgrounds with my son (now six years old), helping him to learn the basic concepts of programming.
Alongside Swift Playgrounds, my son has also been learning via different iPad apps (e.g. Kodable) and is a regular player of Roblox and Minecraft, which (can) incorporate programming concepts.
Therefore, we decided to take these new skills and attempt to build his first app using Swift Playgrounds 4.
As with any project of this type, finding an idea with a defined scope is critical. For example, an app that would appeal to a six-year-old, and could be developed in around 30mins (maximum attention span).
This led me to the excellent tutorial “Build your first SwiftUI app with Swift Playgrounds 4 for iPad” by Paul Hudson. I have embedded the video below, which outlines the process end-to-end.
The app displays a list of personalised photos, which play a custom sound when tapped. It can be developed in around 30 lines of code and includes key concepts such as SwiftUI views, modifiers, use lists, grids, images, buttons, and even the use of a third-party Swift package from GitHub.
My son and I worked together on the app, with him typing/tapping, whilst I provided commentary as to “what” and “why”.
Thanks to the new code completion capabilities of Swift Playgrounds 4, my son was able to start typing (first few letters) and then select from a list to complete the line of code. Now that he is old enough to read, this was an engaging way of coding, as the process of finding the right code snippet was like a mini-game in itself.
All media (photos and sounds) were created and imported into the app directly on the iPad using the included camera and sound recorder apps. This worked well, as it broke up the coding with some fun elements. For example, my son enjoyed making silly sounds, especially when he realised he could make my photo fart.
The entire process took us around 40mins, resulting in a fully functioning app that can be compiled and executed directly from the iPad (no Apple Developer Account required). The full code (minimum viable product) can be found below.
Following the initial release, my son went back and modified the code by repeating the previously learnt steps to add his mum and sister (three years old). This was gratifying, as it demonstrated his understanding and allowed other members of the family to contribute.
Overall, I am impressed with Swift Playgrounds 4. I am excited to see Apple add more advanced capabilities to the app, highlighting a future where end-to-end development could be viable on an iPad. I did notice a few small bugs, but they did not impact the experience and were easily mitigated.
I should also reiterate and commend the excellent tutorial created by Paul Hudson! Great work!