Today is the beginning of Project 5 in the 100 Days of Swift challenge. After the struggles I had with the Challenge tasks of Project 4 I will admit I am just slightly cautious about thinking I had this. Thinking back at the Learning Curve I described yesterday, I’m probably at the first trough which I defined as, “What was I thinking? This is Hard!”
At first I thought I was at the “Yeah, I got this!” phase but then first thing out of the gate with today’s tasks was an article on Capture lists in Swift: What’s the difference between weak, strong, and unowned references?. I’ll be honest, I have now read that article four times, I have entered the code from the article into a Swift playground and tried to dissect what it was doing and I am still completely lost.
I get that I should try to use [weak] for the capturing method because it has less of a chance of causing a memory leak (in the device running the code, not in my brain. I’m afraid I have a perpetual memory loss and no amount of capture lists or any other construct is going to fix that; or so my wife tells me). I think I understand that if I use “unowned” (not “unknown” which I typed in the playground first and I swear Xcode actually laughed at me). But I’m still not exactly clear where this fits within a real-world application. I’m hoping that during the Project 5 lectures and assignments I will finally get a grasp on this.
The project itself sounds fun, creating anagrams from words. Paul Hudson has a great way of teaching that brings things to life, so I am hoping to start digging myself out of the learning curve trough. One thing of note, this project starts with a Table View Controller but when you create a new project it creates it with a View Controller instead.
In the Setting Up phase of the project we’re asked to modify lines at the top of the View Controller file to change the class from UIViewController to UITableViewController. You then need to go into the main.Storyboard and change the view controller class and then embed a Navigation Controller. To me a shortcut is to delete the View Controller Swift file from the file manager and add a new file that uses the UITableViewController class. Then go into the main.Storyboard and delete the Root View Controller so you have a blank storyboard. Then add a Navigation Controller which will automatically add a Table View Controller and connect them for you. Then select the Table View Controller and using the Identity Inspector point it to the Table View Controller file you just created. It does the same thing, but it does make sure things are corrected and the file name for the Table View Controller matches what it is.
The other reason I like doing it this way is that the default file created with a UITableViewController already has the code for numberOfRowsInSection and cellForRowAt functions that we always need for a table view. It just saves a little bit of typing.
Tomorrow I’ll follow this up with the completion of Project 5 including the three challenges.
0 Comments
Trackbacks/Pingbacks