It could be possible to use an intermediate type to help address static isolation differences. This can be particularly effective if the protocol requires inheritance by its conforming types.
class UIStyler {
}
protocol Styler: UIStyler {
func applyStyle()
}
// actors cannot have class-based inheritance
actor WindowStyler: Styler {
}
Introducing a new type to conform indirectly can make this situation work. However, this solution will require some structural changes to WindowStyler that could spill out code that depends on it as well.
Here, a new type has been created that can satisfy the needed inheritance. Incorporating will be easiest if the conformance is only used internally by WindowStyler.
I faced the compile issue: Non-class type 'CustomWindowStyle' cannot conform to class protocol 'Styler'
I didn't fully understand this technique, so I'm not entirely sure how to use it. Perhaps this variant is what is intended:
class UIStyler {
}
protocol Styler {
var uiStyler: UIStyler { get } // Protocol requirement
func applyStyle()
}
struct CustomWindowStyle: Styler {
var uiStyler: UIStyler = UIStyler() // Protocol conformance
func applyStyle() {
// Style implementation
}
}
However, I am still not sure if this is the correct approach. Any guidance or suggestions would be greatly appreciated.
Thanks so much for pointing this out. A fix has been proposed, but I'll include it here.
// class with necessary superclass
class CustomWindowStyle: UIStyler {
}
// now, the conformance is possible
extension CustomWindowStyle: Styler {
func applyStyle() {
}
}
Hello. I'm still confusing about what this topic(Conformance by Proxy) want to say, and what 'static isolation' means.
They want to say the actor can't inherit the class? or what?
Could anyone explain about this?