Casting an Int to a Float

To cast an Int to a Float:

This is useful if you’d like to generate a random float:


2048 implemented in Swift

There’s a new game clone of the 2048 game written in Swift: The author also provides some feedback on Swift:

  • Great language, feels like programming in Scala
  • misses closure based callbacks for UIKit – selectors seem like a hack in Swift
  • private, public, protected for class properties seem missing
  • initializing n-dimension arrays is painful
  • XCode still very unstable

Debug SKPhysicsBody with Swift

Here’s a small extensions that will help you debug SKPhysicsBody Objects using Swift:

You can use it like this:


Swift support for vim

There’s already a project on github to support Swift coding in vim:

To install using NeoBundle, put this in your .vimrc:

Then run :NeoBundleInstall


For loops

Iterate by incrementing or decrementing a value

To iterate over an array in Swift:

To iterate over a dictionary in Swift:


“FlappyBird” clone using Swift

The folks at created a “FlappyBird” clone using Swift. You can view the code on github. If you browse the code you’ll notice how readable and expressive Swift is – the whole codebase is just around 400 lines of code!