<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif"><div style="font-family:menlo;font-size:13px;margin:0px;line-height:normal">Why not making State as a class? EffectiveState should be subclass of State.</div><div style="font-family:menlo;font-size:13px;margin:0px;line-height:normal"><br></div><div style="font-family:menlo;font-size:13px;margin:0px;line-height:normal">Zhaoxin</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 3, 2017 at 11:08 PM, Rudolf Adamkovič via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><div><blockquote type="cite"><div>On 3 Apr 2017, at 16:48, Adrian Zubarev &lt;<a href="mailto:adrian.zubarev@devandartist.com" target="_blank">adrian.zubarev@devandartist.<wbr>com</a>&gt; wrote:</div><br class="m_3185120334291325452Apple-interchange-newline"><div><span style="font-family:Helvetica,Arial;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(254,254,254);float:none;display:inline!important">Why do you cast against an existential in first place?</span></div></blockquote></div><br></span><div>To avoid force-unwrap at the end here:</div><div><br></div><div><div style="margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">class</span><span style="font-variant-ligatures:no-common-ligatures"> Store {</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">var</span><span style="font-variant-ligatures:no-common-ligatures"> state: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">State</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000">    </span><span style="font-variant-ligatures:no-common-ligatures">// ...</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> processScheduledActions() {</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">guard</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">var</span><span style="font-variant-ligatures:no-common-ligatures"> effectfulState = state </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures">? </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Effectful</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">else</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">            </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        }</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">while</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> actions = effectfulState.<wbr>scheduledActions.flush() {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">            </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">for</span><span style="font-variant-ligatures:no-common-ligatures"> action </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">in</span><span style="font-variant-ligatures:no-common-ligatures"> actions {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">                delegate?.store(</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">self</span><span style="font-variant-ligatures:no-common-ligatures">, didRequest: action)</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">            }</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        }</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">        state = effectfulState </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures">! </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">State</span></div><p style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures">        </span><br class="m_3185120334291325452webkit-block-placeholder"></p><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    }</span></div><div style="margin:0px;line-height:normal;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div><br></div></div></div><div>Thank you!</div><span class="HOEnZb"><font color="#888888"><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">R+</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></font></span></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>