Skip to content

Instantly share code, notes, and snippets.

@insidegui
Created October 12, 2017 21:26
Show Gist options
  • Save insidegui/f63dad60fd9a99cc23f976d0a1283286 to your computer and use it in GitHub Desktop.
Save insidegui/f63dad60fd9a99cc23f976d0a1283286 to your computer and use it in GitHub Desktop.
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment