Days 1 to 12 of the “100 Days of Swift” course make up the “Introduction to Swift” section.
Day 6‘s lesson covered closures (part 1 of 2). The specific topics were: creating basic closures, accepting parameters in a closure, returning values from a closure, closures as parameters, and trailing closure syntax
Thoughts about Day 6
The intro for Day 6’s lesson begins with “Brace yourself, because today we’re covering the first thing in Swift that many people have a hard time understanding.” I think that opening line must have seeded my mind the expectation of closures being a hard concept to understand because I found Day 6, part 1 of closures, confusing to understand.
It took me 2 hours 15 minutes to complete the Day 6 lesson and I ended the lesson feeling like I had a poor grasp of closures.
After a break time of several hours I decided to start working on the Day 7 lesson, which is part 2 of 2 of closures. Because I had a poor grasp of Day 6’s closures lesson I found myself thoroughly confused after one hour into Day 7’s closures part 2 lesson. I decided stop work on Day 7 and return to Day 6’s lesson and work through it again.
Day 6’s lesson on closures was so much easier to understand the second time around.
Some notes that I made while working through the Day 6 lesson:
- 1. Creating basic closures
- Second time through
- (referring to the topic’s given example) the print statement inside the closure example is a function with no name that is assigned to the constant named driving.
- the no-name print function is “enclosed” or “closed inside” the braces of the constant named driving.
- the how and why a basic closure is formatted the way it is makes so much more sense the second time studying the Day 6 material.
- Second time through
- 2. Accepting parameters in a closure
- First time through
- closures don’t use parameter labels when called
- closure parameters are defined
- Second time through
- a closure’s parameters are located AFTER the closure’s first open brace to prevent Swift from confusing the parameters as a tuple for the let or var that the closure is assigned to
- closures CANNOT use external parameter names
- First time through
- 3. Returning values from a closure
- Second time through
- parameter names are NOT used when calling closures
- Second time through
- 4. Closures as parameter names
- Second time through
- The closure parameter’s component of () -> Void translates to “accepts no parameters and returns a Void (aka nothing)
- Second time through
- 5. Trailing closure syntax
- First time through
- need to work through this ‘trailing closure syntax’ section a few more times to better understand it
- First time through
It took me 2 hours 15 minutes to go through all of material (videos, main and Optional texts, links to external additional reading materials, and Tests) given for the Day 6 lesson on my first run. For my second time working through Day 6 on the same day it took me 1 hour 30 minutes to complete.
Today’s total study time: 3 hours 45 minutes
100 Days of Swift cumulative study time: 15 hours