Xcode 10.2/10.2.1 – Swift 5 enum with associated values enters incorrect case

Hi everyone,
I just updated one of my projects to Swift 5 and have a pretty weird occurrence. I'm using a GKStateMachine to handle states for a game. When entering a state I also set the value of an enum to the related case for cleaner communication to the outside (delegation for UI etc…). Now after the update to Swift 5 this isn't properly working anymore. For example when setting the StateMachines state to GamePausedState (can be seen in the example) it should also set the current state of the enum to .paused but instead it enters .preparing
The enum contains multiple cases with associated values. Removing those fixes the issue.
I think the root of the problem might be the multiple/nested associated values.

Same outcome in both Xcode 10.2 and Xcode 10.2.1

Example Playground that reproduces the issue: https://www.sendspace.com/file/qudvzt

Hope this isn't a duplicate.

Thanks and best regards

Example Playground that reproduces the issue …

Hmmm, that’s a lot of code (well, the playground itself is small but the States.swift embedded within it is quite chunky. Can you take a shot at distilling that down into a small test case? It’s probably best for you to do that, seeing at you know your code better than anyone here.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

Looks like a bug to me. I tried moving everything in States.swift to the playground file and your state machine acted as expected.

Terms of Service

Privacy Policy

Cookie Policy