Simple Data types
- Booleans
- String (interpolation?)
Booleans
Boolean store binary data true || false
How to store truth:
// the method invocation returns a new value // so instead of doing this let filename = "file.jpg" print(filename.hasSuffix(".jpg")) // you can store the returned value let doesFilenameHaveASuffix = filename.hasSuffix(".jpg") print(doesFilenameHaveASuffix)
Fun fact: Booleans are named after mathematician, George Boole who put in at least 10,000 hours researching and writing about logic
Negating a boolean is simple with the use of the exclamation point
var someVal = false someVal = !someVale // true // or you can do someVal.toggle() // true
Scored 6/6 Doubles and Booleans
How to join strings together
Swift has string interpolation to show information based on data that may be changing.
- Concatenation
- String Interpolation
Concatenation works like this:
let a = "a string " let b = "is a type" let c = a + b // a string is a type let d = c + " of data" print(d)
Interpolation work like this:
let name = "Al" let age = 44 let message = "Hello, my name is \(name) and I'm \(age) years old"
Did you know: Calculations can be included in the interpolation.
Scored 6/6 String interpolation
Summary: simple data
- Constants are created with let, variables are created with var
- Strings contain text, from short strings to novles
- Strings are created with double quotes on both ends
- Multi line strings are created with triple double quotes at both ends
- Swift calls whole numbers integers
- Decimals are called Doubles
- True/false are stored in booleans
- Interpolation let us place data into strings