Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12343] Property Wrappers: Allow multiple enclosing-self subscripts #54777

Open
swift-ci opened this issue Mar 11, 2020 · 1 comment
Open
Labels
compiler The Swift compiler in itself improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12343
Radar rdar://problem/60832290
Original Reporter cbarrett (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

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.

@beccadax
Copy link
Contributor

@swift-ci create

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

2 participants