Swift Playgrounds 4: Entertainment or Productivity

Published on

Get weekly handpicked updates on Swift and SwiftUI!

Just before the end of 2021, Apple finally released Swift Playgrounds 4, arguably the most revolutionary version in recent years. Swift Playgrounds 4 offers the ability to develop distributable apps on the iPad. This article introduces the new features of Swift Playgrounds 4 and explores its feasibility as a development tool.

This article specifically refers to the iPad version of Swift Playgrounds 4. The MacOS version of Swift Playgrounds 4 still uses the 3.x engine. The MacOS Playgrounds 4.1 version has switched to the same core as the iPad version.

About Swift Playgrounds

Two years after the launch of the Swift language, Apple introduced the iPad version of Swift Playgrounds at WWDC 2016.

Swift Playgrounds advocates learning serious coding in a fun way. It doesn’t require users to have programming knowledge, making it very suitable for beginners. Using an interactive teaching mode, Apple provides a series of courses to meet the needs of people aged 4-15.

image-20211219194032374

The course content shown in the image above has a core logic very similar to the Logo language from decades ago, making it extremely suitable for young children.

Perhaps influenced by the “Everyone Can Practice” concept of ancient Chinese martial arts, Apple proposed the “Everyone Can Code” initiative. By providing a large number of iPads and Macs to public schools and teachers in the United States, Apple hoped to vigorously promote the Swift language in the education system. After several years of operation, the program achieved certain results, but the effect did not fully meet expectations.

Meanwhile, smart toy manufacturers also discovered the potential of Swift Playgrounds, introducing courses that work with it, making Swift Playgrounds an important tool in the field of educational toys.

Swift Playgrounds is a typical edutainment product, with its initial design goal not involving the productivity needs of professional development.

Starting from version 3.x, Swift Playgrounds gradually added some features suitable for professional developers, such as:

  • Shared Swift files similar to Xcode Playground
  • Better keyboard and mouse support (with the enhanced capabilities of iPadOS)
  • The ability to display print() statement output in the console, etc.

Some Swift developers gradually started using Swift Playgrounds for small-scale development work.

As iPad performance continuously improved, especially after Apple launched the advertising slogan “Your next computer is not a computer” for the iPad Pro, many Swift developers called for Apple to provide an iPad version of Xcode.

When Apple announced at WWDC 2021 that they would provide an application on iPad that could develop apps like Xcode, people were shocked and looked forward to its early appearance.

Eventually, at the end of 2021, Apple integrated the features showcased at WWDC 2021 into Swift Playground and released the Swift Playground 4.0 version.

New Features of Swift Playgrounds 4

Added Support for Xcode Playground File Format

Although the name Swift Playgrounds is obviously influenced by Xcode Playground, for a long time, its file format was not compatible with Xcode Playground.

Swift Playgrounds used a package called playgroundbook to manage courses and code created by developers. It was difficult for developers to inject other resources into it, limiting the flexibility of writing code in Swift Playgrounds. By providing support for playground packages, developers can work in a more familiar way, gathering and testing ideas, and switching between Mac and iPad at any time.

Click “View All” at the bottom of the homepage and select one of the Xcode Playgrounds.

image-20211224160807063

In fact, in the Playground mode of Swift Playgrounds, apart from not being able to specify the end of the code, the user experience is already very close to that of Xcode Playground.

image-20211219194001850

Perhaps because the iPad can only split into two screens at most, when debugging code in playground mode with Swift Playgrounds, I achieved better focus than on the Mac.

Developing iOS Apps on the iPad Ready for Release

The most eye-catching new feature in Swift Playground 4 is the ability to build applications directly on the iPad using Swift Playgrounds (requires iPadOS 15.2). The projects use a swiftpm package, which is entirely consistent with the SPM structure. These can be opened in Xcode and further edited.

image-20211219200232619

Applications are limited to using the SwiftUI lifecycle, providing a responsive preview and a full-screen running mode, and support adding third-party SPM libraries.

image-20211219195937459

Developers can use options similar to Xcode’s +Capability to add system features the application is allowed to call.

image-20211219200610143

With a developer account, applications can be submitted directly to the App Store for review.

image-20211219200946451

In theory, developers could complete an iOS application ready for launch and distribution using only Swift Playgrounds, without the need for a Mac.

Improved Code Completion and Help

Before version 4.0, Swift Playgrounds used a touch-screen-friendly code completion mechanism:

image-20211219201452934

This approach was not suitable for developers accustomed to the completion mechanisms of professional IDEs. In version 4.0, Swift Playgrounds offers code completion and hints very similar to Xcode in both playground and app modes, greatly improving the efficiency of code writing.

image-20211219201734240

Good support is provided for both system documentation and user-created Markdown comments.

image-20211219202725921

Full Support for Swift DocC

Apple has provided numerous new courses for Swift Playgrounds 4, mainly focused on how to create apps and how to use SwiftUI. Apple has abandoned the previous method of creating courses through PlaygroundBookTemplate and has instead utilized Swift DocC to organize teaching content.

image-20211219203541692

Swift DocC is easier to write than PlaygroundBookTemplate and more suitable for advanced language teaching. Additionally, creating a single set of Swift DocC courses can support both iPad and Mac platforms. Given this, it’s likely that more official and third-party quality courses will emerge soon.

Appropriate Audience or Scenarios for Swift Playgrounds 4

Since Swift Playgrounds 4 now offers so many features for professional development needs, can it be treated as a serious productivity tool?

After several days of continuous use, I believe Apple has not completely changed the positioning of Swift Playgrounds to please professional developers; it still focuses on educational purposes but offers some features suitable for professional developers.

Swift Playgrounds has been developed for 5 years, and its large user base should have acquired sufficient basic Swift programming skills. Version 4.0 provides them with a pathway and means to further improvement. Through more professional playground and app modes, students who originally used Swift Playgrounds with an entertainment mindset are transformed into more professional developers.

Key limitations of Swift Playgrounds 4 in terms of professional development use include:

  • In playground mode, it’s impossible to import SPM (which is possible in Xcode through project or workspace); currently, you can only import source code into the Source directory to test some SPMs.
  • App mode lacks debugging functionality.
  • App mode has insufficient system feature options, especially lacking any functionality related to iCloud services.
  • It’s impossible to develop projects solely related to CoreData, SpriteKit, SceneKit, etc., on your own; similar projects require extensive work on a Mac.
  • App Store submission options are clearly insufficient, with a more demonstrative intent (not ruling out Apple introducing a special type of developer account, such as for students, with cheaper, limited app pricing mechanisms, limited distribution range).
  • There is no resource management, no setting for localized resources, etc.

Considering the positioning of Swift Playgrounds, I believe Apple will only supplement a few professional features in future versions. Perhaps at the right time, Apple might provide an iPad version of Xcode for professional developers (although I think the likelihood is low).

The current version of Swift Playgrounds is suitable for the following audiences or scenarios:

  • Children and students interested in programming (traditional strength area).
  • People with programming needs for smart toys.
  • Users who have mastered basic Swift programming skills and need further improvement.
  • Developers or programming enthusiasts who want to get into iOS and Swift programming but don’t have a Mac, can enter the iOS development ecosystem at a very low cost with Swift Playgrounds (which runs quite smoothly even on iPads from several years ago).
  • Professional Swift developers use playground mode to realize inspiration, test ideas (closest to the Mac experience in terms of productivity).
  • Professional Swift developers continue work on unfinished projects from the Mac in Swift Playgrounds App mode on the iPad (requires converting the project into Swift Playgrounds App mode).

Conclusion

With the winter break approaching, perhaps you can let your child learn some programming through Swift Playgrounds on the iPad in addition to entertainment. Sharing an app they developed with classmates will surely bring considerable pride and satisfaction.

Professional Swift developers should not miss out on Swift Playgrounds, an excellent tool, to further explore the potential of the iPad.

Swift Playgrounds, while retaining its fun educational functionality, meets some productivity needs in certain scenarios.

I'm really looking forward to hearing your thoughts! Please Leave Your Comments Below to share your views and insights.

Fatbobman(东坡肘子)

I'm passionate about life and sharing knowledge. My blog focuses on Swift, SwiftUI, Core Data, and Swift Data. Follow my social media for the latest updates.

You can support me in the following ways