BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Rollout Aims to Enable Live Updates for Swift iOS Apps

Rollout Aims to Enable Live Updates for Swift iOS Apps

This item in japanese

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
Style

BT