Why code on an iPad?

Exploring iOS 10 (dev beta 4)

Playgrounds as developing environments

iPad Playgrounds might not qualify as a full-blown IDE (nor was it designed as such), but clearly it can be used as a form of developing environment.

Take debugging as an example. The side-by-side execution typical of playground coding environments is actually a fairly powerful and intuitive debugging system. When you run your code, you can see the counter for the various methods in your code incrementing. So if you haven’t wired a gesture recognizer up correctly, it’s obvious immediately that those methods aren’t firing. Being able to add viewers to objects, to inspect them as the program is running, is also immensely valuable (try print-ing an object, and adding a viewer to the print statement, if the default viewer for the object isn’t showing anything helpful).

The compiler in the iPad Playgrounds app also has very similar error checking to its Xcode counterpart, including tappable “fix-it” suggestions, which helps eliminate certain types of bug before your code even runs.

Despite all this type-safety in Swift, it is not always going to be the case that “if it compiles, it runs”. Run-time errors can of course still happen in Swift, and this is an area where Playgrounds is not so strong (Xcode Playgrounds is also not great here). At present it appears to have almost no run-time error messages, just an alert telling you to “check your code for mistakes”.

Although in theory Playgrounds places “the entire iOS SDK at your fingertips.”, there are going to be some operations that don’t make sense outside of the context of an app. For instance, code that in an app would require special permissions to be used (for instance by adding a setting to the app’s Info.plist) doesn’t appear to function in my testing of iPad Playgrounds. So far, in terms of what I’ve tested, you cannot:

  • Get the device’s current location using Core Location’s CLLocationManager, presumably because this requires a privacy string to be set in the app’s Info.plist explaining why access to the user’s location is being asked for.
  • Make a URLRequest to a cleartext http:// resource, as this would fall foul of transport security and would require the URL to be white-listed in Info.plist

I’ll update this post as we explore further.

Despite these restrictions though, there’s no doubt that in addition to being a tremendously exciting educational resource, Playgrounds on iPad is also an intriguing developing environment. It offers the chance to develop some of your code on the platform that your app will eventually run on, and for certain stages of the development cycle, that’s a valuable option to have.

Built with Jekyll      © Salt Pig Media