Sandra L Course Part 4 (lectures 23 to 29)
Well, what a busy time it has been - hence the lack of entries! Not going to go into detail; I just want to crack back on with my work! I have missed it and am not going to recap anything at all, just continue with where I got to. So far, Sandra's course has been easy but useful for some consolidation. I'm sure it will get harder soon!
Start Time - 19:15
If/else statements
If statements - that all seems pretty logical so far.
Start Time - 19:15
If/else statements
If statements - that all seems pretty logical so far.
let temp = 20
let sun = "Sunny!"
let clouds = "Cloudy!"
if temp >= 20 {
print(sun)
} else {
print(clouds)
}
Another example -
if temp >= 20 {
print(sun)
} else if temp > 10 {
print(clouds)
} else {
print("Awful weather!")
}
They key thing here is that the if/else block is followed in order. If more than one statement is true - like in the one above (temp being treater than/equal to 20 as well as greater than 10) then the top line is executed as it does it in order.
Switch statements
No need to go through in any more detail!
Structures
Oh here's a cool feature -
var name = "david mitchell"
name.capitalized
So using the 'capitalized' property means that "David Mitchell" is returned!
Classes
class Person {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
}
Enumerations
Weather forecast example - creating an enum, then a switch statement within a function.
There's more to this but to be honest, I just wanted to skim through. At some point, I may revisit the steps to create code that combines so many elements of Swift. For now, it was just good to see how that can happen and it is worth bearing in mind for the next Xcode project that I work on.
Finish Time - 19:55 (40 minutes total)
So there we go, that's the end of Chapter/section 4. Next time, tomorrow morning, it will be chapter 5! I will really make an effort to code along this time and try out different things, then make my own version of the code so I can actually learn more!
Comments
Post a Comment