In time for the end of 2021, Apple has finally released Swift Playgrounds 4, one of the most revolutionary versions in recent years that offers the ability to develop distributable apps on the iPad. This article will take a look at the new features of Swift Playgrounds 4 and explore its feasibility as a development tool.

The original post was posted on my blog wwww.fatbobman.com

Welcome to subscribe my public account: [Elbow’s Swift Notepad]

Swift Playgrounds 4 in this article refers specifically to the iPad version. Swift Playgrounds 4 on MacOS is still powered by the 3.x engine.

About Swift Playgrounds

Two years after the Swift language was released, Apple launched Swift Playgrounds for iPad at WWDC 2016.

Swift Playgrounds promotes a fun way to learn serious code. It doesn’t require programming knowledge and is perfect for beginners. Using an interactive teaching model, Apple offers a range of courseware to meet the needs of people aged 4-15.

The content of the courseware in the figure above is very similar to the Logo language several decades ago, which is very suitable for young people.

Perhaps influenced by the “Everyone Can Code” concept of “Ancient Chinese boxing”, Apple came up with the “Everyone Can Code” program. By providing a large number of ipads and Macs to public schools and teachers in the United States, the hope is to promote Swift in the education system. After several years of operation, this plan has achieved certain results, but the effect has not completely reached the expectation.

At the same time, smart toy manufacturers also saw the potential of Swift Playgrounds and launched courseware to match it, making Swift Playgrounds an important tool in educational toys.

Swift Playgrounds is a classic edutainment product that was originally designed without addressing the productivity requirements of professional development.

Since version 3.x, Swift Playgrounds has gradually added features suitable for professional developers, such as:

  • Shared Swift files similar to Xcode Playground
  • Better keyboard and mouse support (with improved keyboard and mouse capabilities in iPadOS)
  • You can display the output of print() statements and so on in the console

Some Swift developers have been experimenting with Swift Playgrounds for some small-scale development.

As the iPad’s performance continues to improve, many Swift developers have called for Apple to provide an iPad version of Xcode, especially after apple’s “Your next computer, why a computer” AD for the iPad Pro.

When Apple announced at WWDC 2021 that it would offer an app on the iPad that could be developed like Xcode, people were shocked and expecting it.

Finally, at the end of 2021, Apple integrated the features shown at WWDC 2021 into Swift Playground with Swift Playground version 4.0.

New features for Swift Playgrounds 4

Added support for Xcode Playground file formats

While Swift Playgrounds’ name is clearly influenced by Xcode Playground, its file format has long been incompatible with Xcode Playground.

Swift Playgrounds uses a package called PlaygroundBook to manage courseware and developer-created code. It’s hard for developers to inject other resources into it, limiting the flexibility of writing code in Swift Playgrounds. By providing playground package support, developers can work in a more familiar way, pooling and testing ideas, and switching between Mac and iPad at any time.

In fact, in Playground mode for Swift Playgrounds, the experience is pretty close to Xcode Playground, except that you can’t specify where the code ends.

Perhaps because the iPad has at most two screens, DEBUGGING code in Playground mode for Swift Playgrounds gave me better focus than on the Mac.

Develop launch-ready iOS apps on the iPad

The most eye-catching new feature in Swift Playground 4 is the ability to build apps directly on the iPad via Swift Playgrounds (requires iPadOS 15.2). Swiftpm package, which is identical with SPM structure, is adopted in the project. You can open it in Xcode and edit it further.

The app is limited to SwiftUI Life Cycle, provides responsive previews, a full-screen mode, and supports the addition of third-party SPM libraries.

Developers can use options like Xcode +Capablility to add system functions that the application is allowed to call.

With a developer account, you can submit your App directly to the App Store for approval.

In theory, developers could create and publish an iOS app in Swift Playgrounds without using a Mac.

Better code completion and help

Prior to version 4.0, Swift Playgrounds adopted a code completion mechanism suitable for a touchscreen approach:

This approach is not suitable for developers who are used to professional IDE completion. In version 4.0, Swift Playgrounds provides code completion and prompt functions that are very similar to Xcode in Playground and APP modes, which greatly improves code writing efficiency.

There is good support for system documentation as well as user-created Markdown comments.

Full support for Swift DocC

Apple has released a number of new courseware for Swift Playgrounds 4, focusing on how to create apps and how to use SwiftUI. Instead of creating courseware through a PlaygroundBookTemplate, apple uses Swift DocC to organize the content.

Swift DocC is easier to write than PlaygroundBookTemplate and more suitable for advanced language teaching. In addition, you only need to create a Swift DocC courseware to support both iPad and Mac platforms. In view of this, I believe that in the near future, there will be more official and third-party excellent courseware.

Swift Playgrounds 4 for people or scenes

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

After a few days of continuous use, I don’t think Apple has completely changed the positioning of Swift Playgrounds to please professional developers. At the moment, Swift Playgrounds is still focused on educational use, but has some features that are suitable for professional developers.

Swift Playgrounds has been in development for 5 years now, and the vast majority of its users should have already mastered the basic skills of Swift programming, and version 4.0 provides them with ways and means to further improve. Through more professional playground and app mode, students who used Swift Playgrounds for entertainment are transformed into more professional developers.

Swift Playgounds 4 has some key features missing for professional development use:

  • SPM cannot be imported in playground mode (it can be imported through project or workspace under Xcode). Currently, only Source code can be imported into Source directory to test part of SPM
  • No debugging function is provided in APP mode
  • In app mode, the system has insufficient function options, especially does not provide any functions related to iCloud service
  • There is no way to develop projects related to CoreData, SpriteKit, SceneKit, etc., all of which require a lot of work on the Mac
  • The App Store submission options are obviously inadequate, and the current demo is more meaningful (we can’t rule out a future where Apple will launch a specific type of developer account (for students, for example), cheaper, limited App pricing, limited distribution)
  • No resource management, no localized resource Settings, etc

Given Swift Playgrounds’ positioning, I think Apple will only make up for a small number of missing professional features in future releases. Maybe apple will make Xcode available for professional developers on the iPad when the time is right (I don’t think it’s likely).

The current Swift Playgrounds works with the following people or scenarios:

  • Children and students interested in programming (traditional areas of strength)
  • People who have programming needs for smart toys
  • Users who have mastered basic Swift programming skills and need further improvement
  • Developers or hobbyists who want to get into iOS and Swift programming but don’t own a Mac, Swift Playgrounds is an inexpensive way to get into the iOS development ecosystem. (Swift Playgrounds worked pretty well even on ipads years ago.)
  • Professional Swift developers use Playground mode for inspiration, testing ideas (closest to the Mac experience in terms of productivity)
  • Professional Swift developers continue their work on the Mac on Swift Playgrounds (by converting the project to Swift Playgrounds App mode) with only the iPad.

conclusion

The winter vacation is coming soon. Maybe you can let your children learn programming through Swift Playgrounds while using iPad for entertainment. When you share your app with other students, you will be very proud and satisfied.

Swift Playgrounds professional Swift developers should not miss out on Swift Playgrounds as an excellent tool to get more out of the iPad.

Swift Playgrounds meets the productivity needs of some scenarios while retaining the happy education function.

I hope this article has been helpful to you.

The original post was posted on my blog wwww.fatbobman.com

Welcome to subscribe my public account: [Elbow’s Swift Notepad]