Ray Wenderlich Fundamentals Course - Part 3

Yes! Finally some momentum. I'm basically going to continue with the Fundamentals. No more than 45 minutes to help out the old eyes!

Start Time - 19:47

More Collections

Dictionaries

Mostly recap I reckon. Key-value pairs, unordered etc.

Interesting - you can't have the same key! Didn't know that to be fair.

Not going to put the whole dictionary in but some stuff you can do:

for (name, pet) in namesAndPets {
    print("\(name) has a pet called \(pet)")
}


let thorPet = namesAndPets["Thor"] ?? "Nothing for thor"


The second one of these is nil coalescing. It's a bit like ternary.

These are pretty cool too:

for (name, _) in namesAndPets {
    print("\(name) has a pet!")
}

for pet in namesAndPets.values {
    print(pet)

}

Challenge time!

All good! One thing to check was adding a new item - needed to use the syntax NOT with update value. 

Sets

Have to store unique values. No duplicates!

Unordered - unlike arrays. 

Use the contains method. So we have .contains, .insert and .remove.

Now comparing sets....

var someSet: Set<Int> = [1, 4, 7, 12]
var anotherSet: Set<Int> = [4, 9, 2, 1]

let intersection = someSet.intersection(anotherSet)
let difference = someSet.symmetricDifference(anotherSet)
let union = someSet.union(anotherSet)

Challenge - no problems!

It's just become clear to me that 'capture' means create a new value from computation on other(s). Just  a sidenote!

Finish Time - 20:36 (49 minutes)

Lots of good stuff here. Nice to recap dictionaries and sets and get a little more practice. One more chapter in this course!

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)