[swift-users] Protocol composition results in EXC_BAD_ACCESS

Rudolf Adamkovič salutis at me.com
Mon Apr 3 10:08:18 CDT 2017


> On 3 Apr 2017, at 16:48, Adrian Zubarev <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+

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170403/76e5b336/attachment.html>


More information about the swift-users mailing list