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

  • robinthakur - Friday, September 23, 2016 - link

    Exactly, I have an S7 edge currently until my iPhone 7 arrives, and what have I customized? Widgets on the home screen and layouts, nothing else. What equivalent does Google have for Swift Playgrounds which is as polished and useful, pray tell? The polish is what gets users using the features rather than being hidden in Android somewhere. e.g. Apple Pay vs Android Pay, there is no comparison.
  • jdickey - Wednesday, September 21, 2016 - link

    If you have a phone older than an iPhone 6 (maybe even 6s), beware.

    On my 5c, notifications are continually getting messed up. Many apps' notifications don't show up in Notification Centre, and you won't know they're there until you unlock the phone. (Great for people sending you dozens of IMs asking "why aren't you replying?!?") Once you do unlock the phone, notifications often get "stuck"; I once had a Facebook IM "(Your friend) has sent you a message" notification that didn't go away for DAYS after I'd already replied to the message.

    Typing is slower than in iOS 9, and the keyboard often "freezes" with a key highlighted as it normally is when you touch it. Three or four seconds later, any keys you've typed since getting "stuck" play back as though nothing had happened and you intended to type 'a' 35 times.

    I'm seeing these and other problems that I never saw before with iOS 9 betas, let alone official releases. For a company that BUILT ITS BRAND on quality and on the primacy of customer experience, iOS 10 is an appalling reminder of how things can Go Horribly Wrong.

    Here's hoping that a 10.1 update comes out SOON and fixes more existing issues than it creates new ones. The Apple from five years ago would never have released a system in this state. I'm not holding my breath waiting for improvement. The main reason I continue to be an iPhone customer is that most of the direct competition I see (e.g., Samsung) have even steeper downsides.
  • korben44 - Thursday, September 22, 2016 - link

    I had an iPhone 6 for about a week.... Sold it and went back to my Lumia 950 XL. Windows 10 Mobile is just better, in my opinion. Again, that's just my opinion. I had ios 10 from beta to release and still feel the same way. Meh.
  • SomeDude2552 - Saturday, October 1, 2016 - link

    FaggotryTech with another article about FagOS. Amazing.
  • Bolang - Thursday, December 1, 2016 - link

    iOS 10 is best.

    http://freeiphone7plusgiveaway.win/
  • jasonwilliams016 - Tuesday, January 31, 2017 - link

    Thanks for the review. Please let me know the
    <a href="http://www.ios11guide.com/">iOS 11</a> release date and review it soon.
  • oranos - Saturday, February 11, 2017 - link

    It's too late. Android has now surpassed in all relevant categories. Experience, features, smoothness. There is no more catching up for apple. The spread will only get worse now.
  • arvinzx20 - Monday, March 13, 2017 - link

    Base in my experience IOS 10 is good latest update of apple and i think ios 11 will also release this year..

    www.hackcollection.xyz/2016/09/free-iphone-7-plus-giveaway-2017.html
  • arvinzx20 - Monday, March 13, 2017 - link

    When ios 7 is release before they have many bugs in this version unlike right now ios 10 still the best.

    http://www.hackcollection.xyz/2016/09/free-iphone-...
  • Punit - Saturday, July 1, 2017 - link

    hi

Log in

Don't have an account? Sign up now