Book Image

Objective C Memory Management Essentials

Book Image

Objective C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Basics of Swift


Swift syntax is very different to Objective-C, while Objective-C has a lot of reliance on C and C++ components such as pointers, strong typing, and so on. Swift is very similar to popular scripting languages such as Python and Ruby with regards to terseness and variable declaration. So, let's look at some basics of Swift to get acquainted with it.

Variable declaration

Swift does away with the need to remember ints, floats, NSStrings, and so on and consolidates all of these type of variables under one type, and that is of the type var. If you are familiar with JavaScript, then the var keyword should not be unfamiliar to you. Swift supports the type inference, where depending on the value that you assign to a variable, it will infer its type:

var welcome
welcome = "Hello world"

This means that the variable, welcome, is inferred to have a string type as I assigned the text Hello world to it. However, if you want to be specific, you can annotate a variable like this:

var welcome:...