This is super old thread, but since I found it while searching for the answer, I will answer it.
From the docs about init(layer: Any):
This initializer is used by CoreAnimation to create shadow copies of
layers, e.g. for use as presentation layers. Subclasses can override
this method to copy their instance variables into the presentation
layer (subclasses should call the superclass afterwards). Calling this
method in any other situation will result in undefined behavior.
So basically that method gets called when CoreAnimation decides that it needs a new copy of your layer. Changing background color triggers this. On iOS this method got triggered when I change strokeColor. If you have some custom vars on your subclass, you need to copy the values in this method (the layer argument is your old layer so you need to typecast it and then copy the custom params before calling super).
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: