Is there possible to support inheriting from a generic type: class classA<T: classB>: T?

Aaand I still have no clue how to replicate that technique. :sweat_smile::face_with_raised_eyebrow: 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.

Imagine something like this:

struct Published {
    private publisher: ObjectWillChangePublisher
    // etc

That perhaps represents a bug, if you could file a feedback for us. I think it may be fixable.

Will do. Out of curiosity, where would the publisher be stored if there are no @Published wrappers on the class that conforms to ObservableObject?

1 Like

:point_up: Exactly my question/issue.

Filed. FB6976699

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:

1 Like

Is this even safe for retroactive conformances? If I do extension UIView: ObservedObject {} will it light up in flames? :eyes:

1 Like

Did you consider doing this with a @propertyWrapper? I think it could become elegant enough ;)

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?