The Basics
Swift does away with the standard of declaring variables by starting with their type names, and instead opts to use a Javascript-like ‘var’ keyword to define any variable.
So for instance in Objective-C where you have this:
NSString *myString = @"This is my string.";
You now have this:
var myString = "This is my string."
Meanwhile constants are expressed with the ‘let’ keyword
let kSomeConstant = 40
In this case kSomeConstant is implicitly defined as an integer. If you want to be more specific you can specify which type it is like so:
let kSomeConstant: Int = 40
With both arrays and dictionaries, they are described using brackets []
var colorsArray = ["Blue", "Red", "Green", "Yellow"]var colorsDictionary = ["PrimaryColor":"Green", "SecondaryColor":"Red"]
No comments:
Post a Comment