Game Development Reference
In-Depth Information
Appendix
A
The Swift Programming Language
Swift is Apple's new programming language intended to be the future replacement of
Objective-C for Mac and iOS development. Some people are referring to it as a functional
programming language, but it is actually an object-oriented programming language with a
healthy dose of generic programming.
One of the most important facts about Swift is that it uses the same LLVM compiler and
runtime as Objective-C, which means Swift and Objective-C code can live side-by-side. It
also has access to all of the Cocoa and Cocoa Touch features you have in Objective-C ap-
plications.
Here are some notable features of Swift:
Closures (similar to Objective-C blocks)
Tuples that return values
Generics
Fast iterators
Structs and enums that support methods, protocols, and extensions
The ability to pass, nest, and return functions
A more advanced switch statement
In this chapter, you will take a quick (you might say a swift ) look at each of the features in
the Swift programming language. I will start by describing each feature and then cement
your knowledge through consecutive examples. I will not cover every aspect of Swift, but I
will cover enough to make sure you can complete all of the examples in this topic.
Before you can continue, you will need to create a Swift project. Here are the necessary
steps:
1.
Open Xcode.
2.
Select File
New Project.
Search WWH ::




Custom Search