iOS: prettify random color for debugging
I've had a look, and think it should be possible to trim down the ColorCluster-logic quite a bit, mostly by tightening up the get(: function a bit. Avoiding some if-elsing and only manipulating the index and count once.
struct ColorCluster {
    static var shared = ColorCluster()
    private init() { }
    
    private let colors: [UIColor] = [.blue, .magenta, .red, .green, .brown, .purple, .cyan]
    private var colorRegister = [String: Int]()
    private var count = 0

    mutating func getColor(for key: String) -&gt; CGColor {
        let countIsOutOfBounds = count &gt;= colors.count
        let nextAvailableIndex = countIsOutOfBounds ? 0 : count
        
        let index = colorRegister[key] ?? nextAvailableIndex
        count = countIsOutOfBounds ? 0 : count + 1
        
        return colors[index].cgColor
    }
}

I also had a quick look at the debug-extension. I haven't actually tested it, but the gist is to go down the functional route when creating the array of method-names:
extension CALayer {
    func debug() {
        // call stack trace, remove methods of the system
        let libs: Set&lt;String&gt; = [&quot;UIKitCore&quot;, &quot;QuartzCore&quot;, &quot;CoreFoundation&quot;]
        
        let methodNames = Thread.callStackSymbols.reduce([String]()) { names, symbol in
            let containingSymbol = libs.filter({ symbol.contains($0) })
            if containingSymbol.isEmpty {
                return names
            }
            return names + [symbol]
        }
        
        var edgeColor = UIColor.black.cgColor // color place holder
        if let name = methodNames.last {
            edgeColor = ColorCluster.shared.getColor(for: name)
        }
        borderColor = edgeColor
        borderWidth = 1
    }
}