Book Image

Learning iOS 8 Game Development Using Swift

By : Siddharth Shekar
Book Image

Learning iOS 8 Game Development Using Swift

By: Siddharth Shekar

Overview of this book

<p>Game development has been simplified with Apple's new programming language—Swift. If you're looking to start learning iOS development then you'll get everything you need - from&nbsp;the absolute basics such as the Xcode interface and takes you all the way to Swift programming.</p> <p>You will take a walk through the creation of 2D and 3D games followed by an introduction to SpriteKit and SceneKit. The book also looks at how game objects are placed in 3D scenes, how to use the graphics pipeline, and how objects are displayed on mobile screens. You will also delve into essential game concepts such as collision detection, animation, particle systems, and scene transitions. Finally, you will learn how to publish and distribute games to the iTunes store.</p>
Table of Contents (18 chapters)
Learning iOS 8 Game Development Using Swift
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Arrays


An array is a consecutive block of memory that holds a certain type of data. It can be a predefined data type, such as int, float, char, string, or bool, or it can be user-defined. Also, arrays are zero-based, which means that the first object in the array is 0.

Arrays can be either of the var or let type. If we create an array of the var type, then we can change, add, or remove the objects from the array similar to how we have MutableArray in Objective-C. If you want an ImmutableArray array in Swift, instead of var, use the let keyword. Arrays in Swift can be declared and initialized as follows:

var score = [10, 8, 7, 9, 5, 2, 1, 0, 5, 6]

var daysofweek = ["Monday", "Tuesday", "Wednesday"]

Now, if we want to declare an array and initialize it later, we can declare it as shown in the following snippet of code:

 var score : [Int]

var daysofweek : [String]

Here, you will have to provide the data type that the array will be storing. It is very similar to defining a regular variable; it...