Our Experiences with Swift and tvOS When Building the MyMoments App

     
By on February 27, 2017

At Mobile Jazz, we always strive to stay on top of cutting-edge technologies.

This winter, we decided to experiment with tvOS, one of the latest platforms in the Apple ecosystem. The goal was to create a tvOS version of the MyMoments iOS app that we had previously already developed for the EDI Institute.

MyMoments is a medical application proposed by the EDI Institute and developed by Mobile Jazz, which helps mentally disabled patients to express themselves through digital imagery.

Through an easy-to-use image editing application, users can create expressive pictures to help communicate their emotions which they may struggle to display as a result of their condition. These images can be combined with music and text to form a slideshow.

The main goal of the tvOS application was to help the EDI team to display images and slideshows created during a support workshop on a large screen, enabling attendees to share with the class which promotes personal recovery,

We’ve had an incredible journey with the MyMoments team, building the iOS application, the web platform and backend. The team at the EDI institute do so much for so many people, and we wanted to do something for them. So we surprised them with an Apple TV and tvOS version of their app.

Design

When we designed the application for tvOS, we had Apple’s guidelines in mind as well as it’s native components. Apple’s native components have been tested and refined for years, they’re usable, readable and are proven to work on larger displays (TV’s as main target device).

The Apple TV’s weakest points is it’s remote. It is however by design and is intended to be basic and limited. You’ll need to simplify the flow your app, which will improve the experience for users.

As it’s not so easy to interact with the device (when compared to others like the iPhone or iPad) tvOS apps generally target media consumption. This didn’t prove to be a problem for us when developing the MyMoments app which primarily deals with images and movies.

tvOS for iOS Developers

We discovered that building a tvOS application isn’t too different from building an iPhone or iPad app. All of the standard frameworks and tools that you’re used to on the iOS platform are present also on tvOS. So if you’re an iOS developer, you can proudly say that you are also a tvOS developer.

UIKit

We discovered that UIButtons, UIView, UIViewControllers and all classes used in any iOS application can also be used also in tvOS. Likewise, all of the patterns, tips and tricks that you already know, can be easily applied also to your brand new tvOS app.

The main difference we noticed is the Storyboard file, which is laid out to represent the TV screen of your user.

Focus Engine

The Focus Engine is big news, as all user interaction with your application is processed using the Focus Engine. As a developer, you’re responsible to tell the Focus Engine which is the current focused view in any screen and how to react to any user input from the Siri remote.

UIKit adds properties and delegates that permit you to interact with the Focus Engine. You can then react to the focus on a specific view and highlight it, or prevent a view from being focused.

tvOS Simulator

Among the simulators shipped with Xcode, you’ll find a tvOS version. By hitting cmd+shift+R, you can toggle a Siri remote simulation. This can take a while to get used to, as you’ll need to press the alt key when interacting with the Siri remote touch area.

My suggestion is to pair a real tvOS remote with your Mac to test with, follow this excellent guide.

Swift

At Mobile Jazz, we write our apps with a Clean Architecture approach. We’ve built a great set of open source tools that are working perfectly with the existing MyMoments iOS app. Many of those tools however, are written in Objective-C.

We wanted to try using Swift for this project, and decided to use a combination of both languages. The project’s core was written in Objective-C (enabling us to reuse our existing tools) and the ViewControllers were written in Swift.

Throughout the development of the MyMoments iOS app, we used our in-house logging tool Bugfender to help us identify issues and eliminate bugs. We’ve since started to write a tvOS SDK for Bugfender which would have hugely helped us when developing MyMoments for Apple TV.

Interoperability

Bridging Swift with Objective-C was super easy, Apple did a great job here. The first time you add a Swift file to an Objective-C project, Xcode automatically creates a bridging header for you.

You simply need to import any Objective-C files you want to expose to Swift into the header and that’s all there is to it.

Pros

Swift is elegant and fast to write. If you’re used to Objective-C syntax, writing Swift code will seem like you’re flying. Your code will look even shorter and more elegant. Swift is designed around safety: variables are always initialized before use, var and let keywords permit control of a variable, and optionals allow you to safely use objects, without the need of nullability checks.

Moreover, the whole programming language and it’s future release roadmap are open source, and Apple are frequently interacting with the community to improve the language.

Cons

The biggest problem with Swift are the tool sets, which we think are still not completely ready for production builds. We experienced several problems during the testing and debugging of the MyMoments application.

Firstly we noticed that Xcode cannot refactor Swift code. If you try it, you’ll receive the following alert:

At the time of writing, this error is currently on Apple’s to-do list, but doesn’t have a date set yet.

Secondly, when combining Objective-C and Swift, the LLDB debugger occasionally crashes, incorrectly translates Objective-C objects and prints random strings or simply just stops working entirely.

Conclusion

We had a great fun building the MyMoments for tvOS app, and really enjoyed playing with Swift. We’re excited to see where how the language develops in the future.

We’re now working with the EDI Institute to prepare an official release for the Apple TV app. For now, you can download the iOS version and check out the EDI Institute’s website to find out more about their mission and programs.

Read the comments
Paolo Tagliani
Paolo is a software engineer with a passion for clean code.He loves trying new things and keeping himself busy.

Want to receive more insightful articles like this? Subscribe here.


By submitting your information you agree to our Privacy Policy