Categories
Uncategorized

“The Flappening” (or: my fixed version of “Flappy Bird” in Swift)

For a while, FlappySwift — an implementation of Flappy Bird put together by the folks at FullStack.io as part of a Swift development course — was the go-to GitHub repo for understanding both Swift and Sprite Kit. Then, Xcode 6 beta 7 happened and…

xcode beta 7 broke everything

At the beginning of the beta period, many of Apple’s APIs returned values as implicitly unwrapped optionals, which I suspect was a quick and dirty way to get a large number of APIs Swift-compatible. As the beta period went on, they started changing the APIs for optional conformance, which means that:

  • If an API call was going to return a value that might be nil, it would do so as an optional, and
  • if an API call would never return a nil value, it would do so as a non-optional.

A lot of the APIs were updated for optional conformance in Xcode 6 beta 7, including Sprite Kit, which means that suddenly a lot of Swift game code broke. Any code that expected to be using PhysicsBody! objects was suddenly dealing with PhysicsBody? objects and therefore wouldn’t run thanks to a crop of PhysicsBody? does not have a member named [SomeMember] errors.

I explained how to fix this problem in an article titled Why your Swift apps broke in Xcode 6 beta 7 and the GM versions, and how to fix them, but I thought I’d do one better.

I decided to fork the FlappySwift repo, make the necessary fixes, and post the resulting working new version on GitHub.

Now there’s a Swift version of Flappy Swift that will compile under the Xcode 6 GM and the optional-conformant APIs. Enjoy!