I’m currently teaching a mobile development course at GA. I’ll be sharing my swift lessons one by one. Lesson 1: Data Types.After reading this blog post you’ll be able to learn and use the basic data types in Swift.I’m going to briefly introduce a data type. Then I’ll show the syntax for creating it and what you can do with it.
Ready, get set, go!
The String datatype is used for storing and manipulating text. You start defining a string by using a double quotes symbol following by your text. Finish defining your string by using a second double quotes symbol.
A boolean can be either true or false. It’s useful in conditions inside control flow statements like if. It also helps with checking whether a certain condition is met.
The Range data type is used to define a range of values. It’s very handy to define long sequences.
An integer describes a whole number without a decimal point. It’s useful for performing any sort of math on whole numbers.
Double / Float
Doubles and Floats are used for numbers with precision. A double is twice as precise as a float.
Array is a zero indexed, ordered collection of elements.Arrays come in handy when you need to store and operate on a collection of elements.
A dictionary is a collection of key value pairs. A value is stored and retrieved from a dictionary by it’s key. Dictionaries are useful for managing different sets of data. For example keeping a track of heroes and their superpowers 😉
Feel free to play with this code in the playgrounds. Every data type has a lot more useful methods on it.
Photo by yukop