Apple, make your .caml format a public API please

Andrew Wiik
iOS Creatix
Published in
4 min readAug 9, 2017

While working on an upcoming jailbreak tweak called “Maize” that is meant to bring the iOS 11 Control Center back to iOS 10 I came across .caml files. I found out these were how apple was animating the Control Center Toggles. After researching the file format more and how Apple was using it I wondered why the API wasn’t a public one.

Wait, what are .caml files?

.caml files are files that store information for core graphics and core animation code in a xml file format. To my best guess CAML stands for Core Animation Markup Language. CAML files can basically store CALayer’s and animations for them. Here is a short example of what the contents of a .caml file may look like:

Bluetooth toggle from iOS 11, renamed to .xml for syntax highlighting

If you have every worked with CALayer’s or any of its various subclass a lot of this may look very familiar to you, like the CATransformLayer or CAShapeLayer. The path property for the CAShapeLayer is very similar to the path of a SVG document , actually a lot of the .caml format can be related to a SVG file.

Animations in a .caml file

Here is what is really cool about CAML files, they can store animations and those animations can be named and then simply invoked via code, here is an example of the same bluetooth toggle except now it has a on, off, and searching state, when in the search state the toggle fades in and out in an infinite loop.

Notice now we have a “states” key and value, this defines all the different “states” this object can have along with how it should animate to each state and how long those animations should last. each state is defined as an LKState, though in reality it is really a CAState, each state has a name along with optionally being “based-on’ aka inheriting from another state. Each CAState can alse define what properties on each CALayer should be changed for that state. When the layers and sublayers were first defined they could be given an id with a number along with a name which is humanized string of what that layer may represent in respect to the overall “design” the file is producing. The id is used to specify what layer you want to do a property change on when you define the changed properties for a state. Then you can define “state transitions” for each state that defines how each property change should be animated via LKStateTransition, which is really a CAStateTransition. CAStateTransition can define durations along with whether certain changes should be keyframe based or just a simple timing curve, both which are in the example above. A CAStateTransition can be defined for every possible “state-to-state” so that your animations always look smooth.

This is all great but why would this be useful for app developers and designers?

Some great apps exist like PaintCode that can take SVGs and convert them to CoreGraphics drawing code for your app, this is great because having your graphic assets of your app be one size fits all can make the overall size of your app smaller and having that in code makes it even better, but the current state of using these apps results in a couple problems I believe. One being that it can make a code base very messy in the long run and a lot of the code these apps produce isn’t very “human readable”. Also most of these apps don’t support animations or the ones that do just produce even more spaghetti code that then causes your app to take even longer to compile. If apple made the .caml file format allowed to be used Apps along with making the corresponding CoreAnimation classes public it could drastically reduce the size of some apps even more and make animations that much more easier for apps to implementation for simple things like glyphs up to complex scenes like a fancy intro screen. You could even for example just have your app download new animations on the fly and then store them in the local user directory. The power of being able to decouple your design assets from your code while allowing those design assets to be vectorized and each have their own animations is a powerful thing. I truly believe Apple’s currently non-public .caml file format and its corresponding private CoreAnimation classes could be the future of iOS Design and Graphic Assets. They would allow even smaller app sizes with even more beautiful graphic assets that can each have their own animations.

More examples of .caml files and how to display them can be found on the public repository for Maize, for how to display them look at the MZECAPackageView class in the MaizeUI folder, and for the actual .caml files look under the Modules folder in various Modules, a good example is the ConnectivityModule. The Maize repository can be found here.

--

--

Andrew Wiik
Andrew Wiik

Written by Andrew Wiik

Owner of @packixrepo, I go under "ATWiiks" elsewhere. Varnish Software Engineer

Responses (1)