<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:1.2em 0px!important">Greetings, fellow Swiftlets!</p>
<p style="margin:1.2em 0px!important">I am very interested to hear what you guys think about method chaining in a similar style to Swift’s bitmask handling.<br>Yes, there’s a healthy discussion on “Setup Closures”, but let’s <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">dispatch_async</code> to start a new (albeit parallel) thread regarding a neat way to access properties.<br>No doubt you’ve found yourself writing something similar to the following:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:black;background:rgb(255,255,255)">someViewController.view.layer.shadowColor = <span class="hljs-type" style="color:rgb(92,38,153)">UIColor</span>.grayColor().<span class="hljs-type" style="color:rgb(92,38,153)">CGColor</span>
someViewController.view.layer.shadowRadius = <span class="hljs-number" style="color:rgb(28,0,207)">5.0</span>
someViewController.view.layer.shadowOffset = <span class="hljs-type" style="color:rgb(92,38,153)">CGSizeMake</span>(<span class="hljs-number" style="color:rgb(28,0,207)">0.0</span>, <span class="hljs-number" style="color:rgb(28,0,207)">0.5</span>)
someViewController.view.layer.shadowOpacity = <span class="hljs-number" style="color:rgb(28,0,207)">0.75</span>
</code></pre>
<p style="margin:1.2em 0px!important">It can be disturbing to see <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">someViewController.view.layer</code> repeated so many times, however we are currently unable to refactor these lines without subclassing and possibly affecting other areas of implementation.</p>
<p style="margin:1.2em 0px!important">What I propose is a natural way of assigning properties on <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">layer</code> with a syntax we are all already used to:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-swift" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:black;background:rgb(255,255,255)">someViewController.view.layer = [
.shadowColor = <span class="hljs-type" style="color:rgb(92,38,153)">UIColor</span>.grayColor().<span class="hljs-type" style="color:rgb(92,38,153)">CGColor</span>,
.shadowRadius = <span class="hljs-number" style="color:rgb(28,0,207)">5.0</span>,
.shadowOffset = <span class="hljs-type" style="color:rgb(92,38,153)">CGSizeMake</span>(<span class="hljs-number" style="color:rgb(28,0,207)">0.0</span>, <span class="hljs-number" style="color:rgb(28,0,207)">0.5</span>),
.shadowOpacity = <span class="hljs-number" style="color:rgb(28,0,207)">0.75</span>
]
</code></pre>
<p style="margin:1.2em 0px!important">Which is of course similar to our belovèd <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">someViewController.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]</code></p>
<p style="margin:1.2em 0px!important">Of course, this is an extreme example of keypath length, however I believe this language feature would still be beneficial for shorter keypaths (think accessing <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">self</code> within closures or the recent proposal to reinstate <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">self.</code>)</p>
<p style="margin:1.2em 0px!important">Using <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">[]</code> instead of <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">{}</code> eliminates the risk of ambiguity if a method such as <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">func layer(c: Void -> Void)</code> has been defined in the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248)">view</code>’s class. Apart from that, I can’t think of any possible conflicts, and as it’s an addition there will be no migration required when moving to a new language version</p>
<p style="margin:1.2em 0px!important">Interested in your thoughts,</p>
<p style="margin:1.2em 0px!important">MaxC</p>
<div title="MDH:CgoKCgoKCgo8cCBjbGFzcz0iIj5HcmVldGluZ3MsIGZlbGxvdyBTd2lmdGxldHMhP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