ReadCAAR.swift
October 12, 2017 ยท View on GitHub
// This only has to be called once in the application's lifetime NSKeyedUnarchiver.setClass(CALayer.self, forClassName: "KFVectorLayer") NSKeyedUnarchiver.setClass(CAShapeLayer.self, forClassName: "KFVectorFeatureLayer") NSKeyedUnarchiver.setClass(CAShapeLayer.self, forClassName: "KFVectorAnimationLayer") NSKeyedUnarchiver.setClass(CAShapeLayer.self, forClassName: "KFVectorGradientFeatureLayer") NSKeyedUnarchiver.setClass(CAShapeLayer.self, forClassName: "KFVectorBitmapFeatureLayer")
let path = Bundle.main.path(forResource: "YOUR_FILE_HERE", ofType: "caar")! let archive = NSKeyedUnarchiver.unarchiveObject(withFile: path) as! [String: Any] let animLayer = archive["rootLayer"] as! CALayer
// You can now add animLayer as a sublayer of a view's layer, // it's possible that the transform property will need to be changed // to scale the animation layer to fit its superlayer, // depending on the platform, you might need to flip the layer // in the Y axis using another scale transform