Swift Slowly: Day 19 - Hacking Swift 2

The introduction of complex data types: Arrays, Sets, and Tuples. I normally get sets and tuples mixed up hopefully not after today. I spent some time going through my older run throughs of the material.

In a previous attempt to make it through the 100 days, I had created an Xcode playground with pages for the different days.

Hacking with Swift playground

I’ll brush this bad boy off and use it to take notes. One of the gripes that I have that waiting for results feels kind of nerve wracking as I’m looking at the little spinner in the corner of the status bar.

I liked using playgrounds sometimes to see if certain lines are valid.

Using raw values with associated types

Apparently, you can’t use raw values with associated types in enums.

This one took a while, but I think this time was just a little more fun to do.

Completed!

Swift Slowly: Day 18

Working through Paul Hudson’s excellent 100 days of SwiftUI. I thought about changing the title to reflect the fact that I’ll be going through this but decided to stick with this to show that it’s part of a greater arch.

Notable things

Having the _ as a number separator is kind of fun to think about because it reminds me that not every language looks at the comma , the same way.

I like the fact that every section that I’ve looked at has an option page on “why” something is the way it is.

A section pointing to why something is the way it is.

Overall, a very good start to an addition of my programming habit!

Swift Slowly: Day 17

The last day of my run through!

I get to run the completed application.

Tomorrow I’ll start going through Paul Hudson’s Hacking Swift tutorials.

Swift Slowly: Day 16

Work got busy and then the Country’s Capital got attacked so I didn’t put any time into my programming.

Well. It’s time to get back to it. I don’t want not working on my task to be a habit!

Section 4: History View

Purpose: Create a simple view for the history of the the user’s scrums.

The tutorial certainly reads very well, but every once in a while, you run into a scenario where I feel that they probably could have made it a little better. For example, in the history view we give the preview a string for the preview. The website doesn’t read very well in the browser page that it’s on.

Long string text in xcode

Of course, it looks a lot better when it is in Xcode.

Long code line in Xcode

I couldn’t stop messing with the code because I wanted the properties for this thing to stick out.

Long command line reformatted

I’m hoping that if I start using source control for this, I’ll be able to go back and refactor a little easier. This might just be attempting to optimize for something that doesn’t need to be optimized.

I need to do some research on how the extension keyword works in swift and at what point. Extension of the history classI think I understand that we placed it here because no other view needs to do a translation of the attendees array. A discussion on refactoring is most likely not going to be part of this tutorial.

I’m going to finish the last section tomorrow.

Swift Slowly: Day 15

This is the last section of the tutorial.

There were a lot of distractions today, but I’m going to finish this so that I can move on.

Section 2: Integrate Speech Recognition

Purpose: Introduce the code that will allow the application to record speech.

Although the time to go through this is pretty quick, you would really want to go back and take your time to understand how it’s calling access.

Section 3: Display Recording Indicators

Purpose: Learn about dynamically toggling interface elements to let the user know that they are being recorded.

It was pretty fun to do this section, but I’m still reminded that I don’t like ternary statement. The reason for this is that the question mark means it’s an optional if it’s next to the variable but it’s a ternary if it’s not. The rest of the statement should let the developer know, but if you are new or coming back to an old code…

Swift Slowly: Day 14

This is the last section of the tutorial and I’m wondering what I’m going to do after this. I’m going to just do one section today because tomorrow is a big work day.

Section 1: Request Authorization

Purpose: Show how to get use of the phones different functionalities like control of the mic.

The first step is to click the “Add (+)” button but it doesn’t show up unless you have the mouse over one of the properties that are already defined. The interface has a lot of white space that could have been used for something like this and it’s a little misleading.

This is the first time I’ve seen autocomplete not work because of case sensitivity.

The string 'priv' doesn't find Privacy.

Swift Slowly: Day 13

Yesterday, I stopped so that I could spend time with my family. I’m going to pick up from the draw an arc spot.

Section 2: Draw Arc

Purpose: Learn about drawing in the application

The tutorial gives me a really good example for a computed property.


private var degreesPerSpeaker: Double {
    360.0 / Double(totalSpeakers)
}

Section 3: Draw the Ring

Purpose: Display the various segments for the speakers.

The following statement just looks wrong.


if speaker.isCompleted,
    let index = speakers.firstIndex(where: { $0.id == speaker.id }) {
}

Are you really saving something by omitting the { and }?

Swift Slowly: Day 12

Today’s tutorial is about drawing. I’m almost done going through the entire tutorial and wondering what I should look at next.

Section 1: Creating the view

Timer view of application.

The code is pretty self explanitory until you get to places where Swift likes to pour on that sweet, sweet clusure syntax.

private var currentSpeaker: String { speakers.first(where: { !$0.isCompleted })?.name ?? "Someone" }

I had to read that line outloud to fully understand it. My brain had more question marks than the line itself. Luckily, I’ve accustomed to optionals thanks to working with Paul Hudson’s tutorials.

Also, there were some wins for the documentation popups.

Showing what properties are available for combine

Section 2: Draw an Arc

Purpose: Create a drawing on top of the circle.

I’m going to stop here because I want to spend some time with my family before bed. It’s my last night of vacation.

Swift Slowly: Day 11

Continuing with learning about persistence tutorial

<img alt srcset=​"https:​/​/​docs-assets.developer.apple.com/​published/​8b6dcf46ffef24b1ac64555436587521/​600/​SUI_100-003.png 1x, https:​/​/​docs-assets.developer.apple.com/​published/​0f0b16a34e0c11fdc102fb25bb806d15/​600/​SUI_100-003@2x.png 2x" src=​"https:​/​/​docs-assets.developer.apple.com/​published/​8b6dcf46ffef24b1ac64555436587521/​600/​SUI_100-003.png" width=​"362" height=​"auto">​

Section 3: Method to Load Data

Purpose: Show how to load JSON

This section is pretty cut and dry and I look forward to what the rest of the application looks like. I like the fact that the tutorial shows how to load test data during development.

Section 4: Saving Data

Purpose: This is where the user’s data gets stored from one run to the next.

This is my first time seeing a do-catch statement. I other languages, I’ve seen it as a try-catch and it doesn’t have a specific line on which we are trying.

do {
	let outfile = Self.fileURL
    try data.write(to: outfile)
} catch {
	fatalError("Can't write to file")
}

Section 5: Save and Load

Purpose: Put the finishing touches on the application.

Other than the part where I put “ObservableObject” instead of “ObservedObject”, I think this was a pretty nice tutorial.

Swift Slowly: Day 10

Today’s tutorial is about persistence. I think that’s a good one as I make my way through these various tutorials.

Section 1: Add Codable

Purpose: Make the models that we’ve been working on conform to a protocal that will allow it to be saved as JSON.

It’s interesting to me that they have file names with special characters like “+” in them for the tutorial.

File names with special characters

It reminds me of when I first got into computers and how the teachers would tell us that it’s a big no-no.

Section 2: Create Data Model Purpose: To show how data can be stored. It touches on the Combine framework.

At this point, I think the tutorial should define the difference between the data in the different scrum objects/classes and the one for persistence. Or maybe they have and I jumped over it.

Documentation seems very sparse.

I like the way the documentation widgets work for the most part, but I would love to get more information from it.

Short cut to documentation

Clicking on the link “Open in Developer Documentation”, doesn’t really give me hope I’m going to get an answer for any question I might have.

Observable Object documentation

In the above picture, how is someone new to this going to know that the declaration has a link ObservableObject protocol?

Observable Object Protocol

Some of the notes feel like they should be closer together.

It feels like certain notes should be close to the steps that they highlight.

Note seperation between steps

Keyboard shortcuts are amazing.

I love ^I for re-indenting my code.

I’m going to stop here and pick this up tomorrow.