Swift Playgrounds

The iPad Pro has become a big part of my daily life. When I'm working, the 9.7" iPad Pro goes everywhere with me as a device for development and taking down information using either Apple Pencil or typed notes. When I'm in classes, the 12.9" iPad Pro is indespensable due to its ability to have two regular size class apps on the screen at the same time, which allows notes to be taken with Apple Pencil while a digital textbook or lecture slides are open on the other half of the display. For me the iPad Pro has replaced my laptop in every way except for one, which is my actual development work. As someone who does mobile development and writes C code for university courses, there's no way to escape using a laptop or a desktop computer to access XCode and Android Studio.

Some people may be wondering why Apple hasn't just brought XCode to the iPad. The simplest explanation is honestly just that bringing the entire IDE to iOS is an enormous undertaking. Apple has brought versions of their software to mobile before, like the iWork suite, but bringing XCode is a whole other story. In many ways it is not clear how to translate the interface of an IDE to a multitouch device like an iPad, and from a functional perspective it would certainly be difficult to bring over all the features that actually enable app development, many of which are just a GUI fronts for tools that are executed in the Unix shell behind the scenes. Allowing a user application to compile code and execute it also presents many questions and concerns regarding security. The list goes on and on, but suffice to say, bringing the entirety of XCode to the iPad is not a trivial feat and it's not near as simple as just making a new UI that works on iOS.

Bringing XCode to iOS might be too large of a project to do without some initial work in place. In many ways, that's where Apple's new Swift Playgrounds app for the iPad fits in. It has two functions. The first is to provide a fun and easy way for new programmers to learn programming concepts. To do this, Apple has provided a way for people in the development community to publish books for Swift Playgrounds that teach users by having them complete programming tasks in a fun and interactive way. 

Apple provides two such books for learning the basics of the Swift language. In them you control a character called Byte who must be moved around a 3D world by walking and traversing through portals to collect gems and activate switches. It's a very interactive way of learning to program, and the books start out with the very basics of programming. Once you've gone through the basics, the sections begin to cover more advanced topics including debugging, algorithm design, and function generalization. There's also some coverage of algorithm efficiency, which is often not discussed enough in formal education or online programming courses. If you're someone who is interested in learning to program and you own an iPad, I definitely recommend checking out Swift Playgrounds. With any luck there will be additional books added by the community to cover more specific topics, such as actual iOS app development.

If you're already familiar with iOS development and UIKit there's still a lot that you can get out of the Playgrounds app. The second purpose of Playgrounds is to give programmers a way to test out ideas in a quick and easy manner. That was the point of XCode Playgrounds on the Mac as well, but with it available on the iPad there's now a way to test ideas even if you're not at your computer. When Apple originally announced Playgrounds I assumed it wouldn't have much use for existing programmers due to UIKit being unavailable or accessible only in a limited manner, making it essentially impossible to prototype ideas that will later be put into real applications. It turns out that this assumption was completely wrong, and from what I can tell the entirety of UIKit is available in Playgrounds, along with direct access to the underlying C-based APIs like Core Graphics and Core Animation.

In the video above I've shown how some UIKit APIs can be used in Swift Playgrounds on the iPad. Since UIKit is available, it would actually be possible to write an application of sorts within Swift Playgrounds, although as of right now I haven't experimented enough to say what sort of sandboxing limitations may exist on APIs that send or receive data over a network. In my video above you can see that creating your own playground presents the same split interface between the code editor and the live view. You can actually long press the separator between the two and move it to bring the editor or the preview into fullscreen, and it uses the same sort of UI as multitasking on the iPad so it's a familiar interaction. 

For my demo I've made a UIView subclass which also draws a button and a second view that I have poorly masked to look like a circle and filled in with red. My intent was that the circle would pulse inward and outward when the button was pressed. As you can see, I actually made a mistake before recording and started animating the outer view pulsing in and out. Since I was already recording I felt it would be a good opportunity to show the code editing in XCode Playgrounds, so I fixed the bug in the middle of the video and made the circle pulse properly as it should have. This is just a very basic example of what can be accomplished using Playgrounds, and I expect that developers who start working with ViewControllers or bring in Apple's other APIs like SceneKit will be able to create some amazing things on their iPads using Swift Playgrounds.

Experienced programmers may be wondering how well the iPad works as a device for programming given that it doesn't have a physical keyboard or any sort of mouse pointer. Apple has actually done a good job of making the iPad's touch interface usable for programming in Swift Playgrounds. The most significant work has been done to the keyboard. It's a special keyboard with shortcuts to common programming symbols that aren't normally accessible on the iPad's keyboard without going into the symbol menu. To access them you simply put your finger on the key and pull the symbol toward you. This is helpful for accessing certain symbols, but it's still not as fast as having dedicated keys. Thankfully, the editor does a good job of automatically placing braces and matching brackets, and there's also a library of pre-formatted code blocks with placeholders so you can quickly drop in a loop or a control flow statement. 

The only big issue with the on screen keyboard is that it takes up a great deal of your workspace. To help mitigate this when users don't have a physical keyboard, the shortcuts bar remains visible on the bottom of the screen unless explicitly dismissed after the keyboard already has been. The autocompletion is also very good, to the point that you can often do your work without actually having the keyboard up. Apple also provides buttons to create a new line or erase an entire line when editing in this mode.

While I said that Swift Playgrounds on iPad has two functions, it's more accurate to say that it has two user-facing functions. I think it has a third function which is specific to Apple, which is to lay groundwork for an eventual version of XCode that will run on the iPad. Swift Playgrounds provides a risk free way to test what the iPad can do with regards to writing and running code, and it allows Apple to experiment with new UI and functionality ideas without having to make the sort of stability and support promises that officially bringing XCode to the iPad would require. Most importantly, it allows Apple to think through what sort of security model is required to allow actual app development on the iPad.

Right now Swift Playgrounds already allows you to do impressive things as a programmer, and for me it is a great tool for testing ideas that come to mind when I'm away from my development machine. Having access to UIKit is huge, and it means that Apple is already giving programmers access to the same API set that is used to develop iOS apps in XCode on the Mac. Expanding this into an actual IDE that can be used to program applications requires Apple to integrate Interface Builder and Clang, plus Apple's own solution for code signing. Of course, even with those, an initial release of XCode for the iPad would be rather simple compared to its macOS counterpart, but the foundation of the IDE will have been laid out to be expanded on in future updates. With Swift Playgrounds Apple has already laid a great deal of that foundation, and I think it's very likely that you'll be able to develop iPad apps on your iPad itself in the not too distant future.

Extending iMessage Under The Hood: Animations, Performance
Comments Locked

113 Comments

View All Comments

  • damianrobertjones - Wednesday, September 14, 2016 - link

    Cash. Money. The usual. Bills have to be paid. The days of complete, free, impartial journalism died years back. The Verge and Engadget being the worst of the many. I see a web page design in the future for Anandtech.
  • robinthakur - Friday, September 23, 2016 - link

    Because people click on the articles more, would be my guess? I scanned the whole site for the iPhone 7 review and clicked on another apple article on iOS10 when I couldn't find it. This is actually a good technical review by somebody who clearly knows the OS inside out, so I've got no problem with it.
  • ABR - Wednesday, September 14, 2016 - link

    The overall UI smoothness improvement is really noticeable on an iPad Air 2. It's a really shame this is the release they decided to cut support for iPad 2 and that era devices, because those are just the ones that became truly unusable starting with iOS 8. Thinking charitably, it could be that dropping the support is one of the things that helped improve the performance, or, more cynically, maybe it's just part of their plan to continue encouraging purchase of new devices.
  • tipoo - Wednesday, September 14, 2016 - link

    Yeah, even if they dropped all the new features, the performance improvements would have been huge for A5 devices. In fact I wouldn't mind if they stripped the OS as much as they could to get A5 smooth again, but of course they're not going to do such an undertaking for the old chip.
  • tipoo - Wednesday, September 14, 2016 - link

    The worst thing about it is no OS security updates for older OSs, so you're forced to either go insecure, or get a dog slow OS on your formerly decent hardware. There's also no easy downgrade mechanism.
  • m16 - Wednesday, September 14, 2016 - link

    I'm very impressed with the update, really snappy. I'm even more impressed that all my apps work, but I don't have any fancy apps outside of some photography apps that control the aperture.

    I wish they'd brought back notification center social media posting. I mean, OS X Capitan has it!!! It had it back on the iOS 7 days.

    Anyone else thinking this should be back should go to apple's feedback page on either iOS or the iPhone/iPad and request the feature back.
  • yhselp - Wednesday, September 14, 2016 - link

    I'm very glad Apple have seemingly fixed performance and UI issues for the 5s compared to iOS 9.

    After upgrading yesterday I was pleasantly surprised. At least for now. I hope I don't jinx it. The 5s is now noticeably smoother; navigating menus, multitasking, and general use overall is now more in line with how fast it used to be on iOS 8. In-app performance seems to have improved as well; I specifically tested an app that used to work great on iOS 8, then ran poorly on iOS 9, and now seems to work great again on iOS 10. Furthermore, the UI itself is now better optimized for a 4-inch display - not only is it better than iOS 9, but there are also improvement over how it used to be on iOS 8.

    So far so good then. Haven't encountered any major hitches, and battery life seems to be holding up. Still, some things are sometimes actually slower than how I remember them from iOS 8, but the opposite is true as well - sometimes the 5s feels faster than ever. Overall, so far, I'd say the smoothness is on par with iOS 8.

    One thing that still baffles me is the Music app. I still pretty much hate it, although it's an improvement over iOS 9 both in terms of usability and 4-inch friendliness. Maybe it's better suited to how most people seem to consume music nowadays - internet music, music services, etc. I can't believe that so few people listen to music in a more traditional way that it's worth ignoring them. Why is it so hard for Apple to at least offer more control over how the music library is sorted? I want to be able to browse by artist, tap on a band, and see all their songs I have on my device in one place with little bars above every group indicating which albums they're from; just as it used to be, and not how it is now. On top of that, the Music app is now less sexy than ever, there's no cover flow at all (at least, I can't seem to find it), and the UI can still get unnecessarily cluttered on a 4-inch display. For me, the best Music app would be a hybrid of how it used to look on iPhone 5 running iOS 6 with some of the improvements from iOS 7 and 8.
  • yhselp - Wednesday, September 14, 2016 - link

    I can't help but think - thank God they made the SE, because without it iOS 10 might not have been as 4-inch friendly as it is.

    I'd be very much interested to hear any impressions on how iOS 10 works on iPhone 5/5c.
  • yhselp - Wednesday, September 14, 2016 - link

    Update: One important thing that has seen a downgrade, in my opinion, is notification banners. When you're doing something, and someone sends you a message the banner that appears on the top of the screen is bigger, gets in the way, and it's harder to reply quickly without opening the Messages app - pulling down the banner is harder, and once done it takes up to whole screen.

    For me, that is a major downgrade as it makes banner more obtrusive on a 4" device, and make it hard to reply to messages quickly. I understand it might have been made in a bid to improve visibility on 4" devices, but I don't think it was the right call.

    This might prove to be iOS 10's Achilles' heel on 4" devices. I would very much like to see it fixed.
  • mdriftmeyer - Wednesday, September 14, 2016 - link

    You'd be wrong. Works great on my iPhone 5s. Notifications now are more easily flipped through and understood at quick glances.

Log in

Don't have an account? Sign up now