BT

Rollout Aims to Enable Live Updates for Swift iOS Apps

| by Sergio De Simone Follow 13 Followers on Nov 06, 2016. Estimated reading time: 2 minutes |

Rollout, maker of a solution that makes it possible to live-update native Objective-C apps without going through the App Store review process, has announced support for Swift. Live-update of Swift apps is achieved through a technique Rollout calls pseudo method-swizzling.

For Objective-C apps, the mechanism that allows Rollout to patch apps is a dynamic programming technique known as method swizzling, which allows developers to change the implementation of an existing method by modifying the way the Objective-C runtime associates the method signature to a function in a class. A swizzled method can be entirely replaced or simply wrapped by a new implementation downloaded from Rollout cloud. Rollout allows developers to define swizzling methods in JavaScript, which is key to make this mechanism compatible with Apple guidelines, that only admit the possibility of downloading code to be run by WebKit or JavaScript Core. Alternatively, Objective-C patches can use pre-defined templates meant to accomplish specific goals, such as adding tracing logs to method calls, disable a method, etc.

Method-swizzling is not natively available in Swift, which has no runtime-programming capabilities, so, as Rollout CTO Eyal Keren explains, they had to develop something similar for Swift. In short, what Rollout does is instrumenting an app at the Swift Intermediate Language (SIL) level by adding a prefix to each method which looks like:

func add(a:Int, b:Int) -> Int {
    if Rollout_shouldPatch(ROLLOUT_a79ee6d5a41da8daaa2fef82124dcf74) {
        let resultRollout : Int =
        Rollout_invokeReturn(Rollout_tweakData!,
            target:self,
            arguments:[a,
                b,
                origClosure: { args in return self.add(a:args[0],b:args[1]);});
        return resultRollout;

In the above code, the Rollout_invokeReturn is responsible to run a JavaScript function that is downloaded from Rollout cloud. This function can call back the original method if required.

In comparison with Rollout for Objective-C, which lends itself to be used in a variety of contexts, support for Swift is still in its infancy, though Rollout is working to improve it. In particular:

  • Swift patches cannot run a native Swift method, unless it is the patched method itself or an @objc method, nor it can create a native Swift object.
  • Return values may be overridden only for a limited number of types, such as String, Number, Optional, and all Objective-C compatible classes.
  • Swift native exception can not be caught.
  • A number of Swift features are not supported yet, such as static class methods, overloaded instance methods, struct methods, etc.

Several of the limitations listed above are already implemented and currently in beta test, according to Rollout.

According to Rollout, their live-update solution, which they claim is currently used in thousands of mobile apps, is totally legit as per Apple’s guidelines.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT