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.
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:...