[swift-evolution] Proposal: 'selfless' keyword for refactoring duplicate code from initialisers
Marc Knaup
marc at knaup.koeln
Tue Dec 15 19:51:51 CST 2015
Although I understand your concerns (Charles and Ross) I think an extensive
example is still necessary to properly discuss this proposal. We'd have to
figure out what exactly causes the limitation, if there are alternatives
and if there is no alternative which would render the change unnecessary.
So far this is a very theoretical discussion.
On Wed, Dec 16, 2015 at 2:48 AM, Charles Srstka <cocoadev at charlessoft.com>
wrote:
> On Dec 15, 2015, at 7:06 PM, Marc Knaup <marc at knaup.koeln> wrote:
>
>
> In its current state with the initial example -1 from me for the proposal.
>
> The example could easily be written like this:
>
> class FooView: UIView {
>
> var property = 4
>
> init() {
> super.init()
> }
>
> init(frame: CGRect) {
> super.init(frame)
> }
> }
>
>
> In cases where the initially value is computed in a complex way a closure
> can be used:
>
> class FooView: UIView {
>
> var property: Int = {
> // some complicated computation
> return value
> }()
>
> init() {
> super.init()
> }
>
> init(frame: CGRect) {
> super.init(frame)
> }
> }
>
>
> That works for simplistic cases such as this. However, if you have a large
> number of properties that all need to be set, and if their values are all
> interconnected in some way, dependent on some of the initializer’s
> parameters, or dependent on some value computed at runtime, this pattern
> cannot accomplish the task cleanly.
>
> Charles
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151216/8f26d509/attachment.html>
More information about the swift-evolution
mailing list