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:


For loops

Iterate by incrementing or decrementing a value

To iterate over an array in Swift:

To iterate over a dictionary in Swift: