ReactKit/SwiftState

Whats meaning of nil => .State2 ? Got an error

Closed this issue · 2 comments

素晴らしいライブラリです
I tried from 0=>2, I got a error, whats meaning of nil => .State2, I think state2 can accept a transform from any other state, isn't it?

    // tryState 0 => 2 => 1 => 2 => 1 => 0
    machine <- (.State2, "Ping") //Any => 2, msg=Ping fatal error: unexpectedly found nil while unwrapping an Optional value
    machine <- .State1
    machine <- (.State2, "Hello")
    machine <- (.State1, "Bye")
    machine <- .State0  // fail: no 1 => 0

I got reason, please remove びっくりマーク ! from context.userInfo.
the "machine <- .State1" don't include userinfo, so it is nil, (context.userInfo!) will raise an exception.

        machine.addRoute(.AnyState => .State2) { context in println("Any => 2, msg=\(context.userInfo)") }
        machine.addRoute(.State2 => nil) { context in println("2 => Any, msg=\(context.userInfo)") }

OK, I just removed unwrapping optionals in 9561e88 for safety. Thanks :)