You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, property wrappers are only allowed to have one declaration of an enclosing-self subscript. However, when writing a generic wrapper, it may be necessary to define the behavior of the wrapper on a type-by-type basis.
For example, I ran into this issue defining a @ NeedsLayout property wrapper that calls self.setNeedsLayout() or self.viewIfLoaded?.setNeedsLayout() depending on if the enclosing class is a view or a view controller.
My workaround was to define a protocol and constrain the EnclosingSelf type parameter to conform to it. Instead of writing two generic subscripts (see below) I wrote instances of the protocol. So aside from the appropriate setter and getter boilerplate which are always the same anyway, the single enclosing-self subscript is simply a type-based dispatch to one or the other protocol implementation.
That works, but it would be better if I could write two subscript declarations, one where EnclosingSelf is a subtype of UIView and one likewise for UIViewController.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: 480e8c9114b3a6ec2ff767ce89ff3ca7
Issue Description:
Currently, property wrappers are only allowed to have one declaration of an enclosing-self subscript. However, when writing a generic wrapper, it may be necessary to define the behavior of the wrapper on a type-by-type basis.
For example, I ran into this issue defining a @ NeedsLayout property wrapper that calls self.setNeedsLayout() or self.viewIfLoaded?.setNeedsLayout() depending on if the enclosing class is a view or a view controller.
My workaround was to define a protocol and constrain the EnclosingSelf type parameter to conform to it. Instead of writing two generic subscripts (see below) I wrote instances of the protocol. So aside from the appropriate setter and getter boilerplate which are always the same anyway, the single enclosing-self subscript is simply a type-based dispatch to one or the other protocol implementation.
That works, but it would be better if I could write two subscript declarations, one where EnclosingSelf is a subtype of UIView and one likewise for UIViewController.
The text was updated successfully, but these errors were encountered: