Book Image

Mastering Cocos2d Game Development

By : Alex Ogorek
Book Image

Mastering Cocos2d Game Development

By: Alex Ogorek

Overview of this book

Table of Contents (15 chapters)
Mastering Cocos2d Game Development
About the Author
About the Reviewers

How Swift works

The main difference between Objective-C and Swift is in the way it looks. It still feels like Objective-C (in the sense that you can call all of the same methods), but the syntax is different.

For example, suppose you want to call this in Objective-C:

[object someMethodWithParam:param1 andOtherParam:param2];

Instead, you end up calling the following in Swift:

object.someMethodWithParam(param1, andOtherParam:param2)

Also, instead of using a header and a main file as in Objective-C, there's only a .swift file that gets used for everything.

There are obviously some syntax differences that you'll have to learn about when it comes to coding in Swift, but those who are familiar with Objective-C will pick up Swift quite easily. Don't worry, even if you aren't familiar with Objective-C. Swift is an easy-to-learn language, which makes picking it up much better.

That being said, let's cover some syntax differences using Apple's new tool they created to help learn and debug Swift—Playgrounds...