I have made the decision to learn Native IOS development using the Swift programming language and produce a portfolio of apps. This page would therefore be updated with everything I learn daily. I am primarily doing this to keep myself accountable to my progress. I’ll be updating my progress in reverse chronological order below:
Update 4
5th April 2020
- Learned the weird for loop syntax:
let count = 1...10
for number in count {
print("Number is \(number)")
}
print("Players gonna ")
for _ in 1...5 { //without using a constant
print("play")
}
- Learned the repeat loop which is basically the same as a do-while loop in other languages:
repeat {
print("This is false")
} while false
- Learned that it is possible to label for loops and use the break keyword with labels to break outerLoops:
outerLoop: for i in 1...10 {
for j in 1...10 {
let product = i * j
print ("\(i) * \(j) is \(product)")
if product == 50 {
print("It's a bullseye!")
break outerLoop
}
}
}
Update 3
4th April 2020
- Learned about range operators. Swift gives us two ways of making ranges: the ..< and … operators. The half-open range operator, ..<, creates ranges up to but excluding the final value, and the closed range operator, …, creates ranges up to and including the final value.
- Range operators are useful in switch statements:
let score = 85
switch score {
case 0..<50:
print("You failed badly.")
case 50..<85:
print("You did OK.")
default:
print("You did great!")
}
Update 2
4th April 2020
- Learned array declaration
- Learned Set declaration:
let colors2 = Set(["red", "green", "blue", "red", "blue"])
- Tuples allow you to store several values together in a single value.
- You can’t add or remove items from a tuple; they are fixed in size.
- You can’t change the type of items in a tuple; they always have the same types they were created with.
var name = (first: "Taylor", last: "Swift")
name.0
name.first
- Dictionaries can be declared like:
let heights = [
"Taylor Swift": 1.78,
"Ed Sheeran": 1.73
]
heights["Eminem", default: "Unknown"] //will give unknown instead of "nil"
- Learned about enums and enum associated values:
enum Activity {
case bored
case running(destination: String)
case talking(topic: String)
case singing(volume: Int)
}
Update 1
3rd April 2020
- Learned that Swift is a type-safe programming language like Javascript.
- Multiline strings would be coded like this
var str1 = """
This goes
over multiple
lines
"""
- String interpolation works like this :
var score = 85
var str = "Your score was \(score)"
- As opposed to Javascript, the “let” keyword defines constants that cannot be changed after declared.
- Type inference is possible by :
let album: String = "Reputation"
let year: Int = 1989
let height: Double = 1.78
let taylorRocks: Bool = true