Aaand I still have no clue how to replicate that technique. How is there an ivar for pure protocol conformance?
@Helge_Hess1 gessed on Slack that you sneak the storage into a Published instance, that would be really sneaking and nonintuitive at all as the protocol does not require that.
Unfortunately I cant really go to far in depth with that at the current moment, but suffice it to say we use memory associated with the object itself (this is part the reason why we require ObservableObject to be a reference type).
I will give a bit of interesting reading that is not completely tangential:
I apologize in advance if this shouldn't be posted on an old topic. But here is a simplified example of a use case that I ran in to. Let's say this were possible:
class NonFirstResponder<T: NSFirstResponder>: T {
var acceptsFirstResponder: Bool { false }
}
With that, any of the AppKit controls can have focusability disabled just by wrapping their type in NonFirstResponder<> when creating:
// A button with stock functionality:
button = NSButton(title: "Something", target: coord, action: #selector(coord.buttonClicked))
// An identical button that doesn't accept focus:
button = NonFirstResponder<NSButton>(title: "Something", target: coord, action: #selector(coord.buttonClicked))
I know the need to disable focusability isn't something that comes up very often. It's just a concise example. There's plenty of other functionality in AppKit besides acceptsFirstResponder that also requires sub-classing to use.
This isn't to dismiss earlier comments that this would be difficult to implement in the compiler. Just providing an example.
... Or is there already some way to accomplish this kind of thing without manually subclassing every type of control you need to use it on?