[swift-users] Protocol composition results in EXC_BAD_ACCESS
Rudolf Adamkovič
salutis at me.com
Mon Apr 3 11:02:12 CDT 2017
Because it’s a value and has no identity.
R+
> On 3 Apr 2017, at 17:58, Zhao Xin <owenzx at gmail.com> wrote:
>
> Why not making State as a class? EffectiveState should be subclass of State.
>
> Zhaoxin
>
> On Mon, Apr 3, 2017 at 11:08 PM, Rudolf Adamkovič via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> On 3 Apr 2017, at 16:48, Adrian Zubarev <adrian.zubarev at devandartist.com <mailto:adrian.zubarev at devandartist.com>> wrote:
>>
>> Why do you cast against an existential in first place?
>
> To avoid force-unwrap at the end here:
>
> class Store {
>
> var state: State
>
> // ...
>
> func processScheduledActions() {
>
> guard var effectfulState = state as? Effectful else {
> return
> }
>
> while let actions = effectfulState.scheduledActions.flush() {
> for action in actions {
> delegate?.store(self, didRequest: action)
> }
> }
>
> state = effectfulState as! State
>
> }
>
> }
>
> Thank you!
>
> R+
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170403/4e42d864/attachment.html>
More information about the swift-users
mailing list