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:
The second one of these is nil coalescing. It's a bit like ternary.
These are pretty cool too:
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
Post a Comment