Categories
Uncategorized

Today Ollie is initiating launch sequence

We’re helping him get set up in residence at Carleton res. Looks like all systems are go…

Categories
Haiku Uncategorized

Random Full Time Employment Haiku

You and me belong
To the Sun. Everyone does,
But you more than most.

Marge thought through laughing
Ivy is more circumspect
Syllables matter

Categories
Software Uncategorized

A SwiftUI Picker Using an Swift Enum

These two items (the SwiftUI Picker and a Swift enum) work really well together. Some might say they go together as well as Peanut Butter and Banana.

Requirement: Your app needs a way for a user to choose how to sort their list items. Today list items can be sorted by Name, Height and Average Score. Some time in the future, the list of sort types is expected to grow.

Eventually we are going to need some UI for this, but let’s start be defining an enum to define the sort types. Our enum needs to conform to CaseIterable because we will need to call the allCases class method. I don’t think String is required, but is helpful in the initial stage before we polish the UI.

enum SortType: String, CaseIterable {
    case name
    case height
    case averageScore
}

And also a Settings model object to store our source of truth (ie sort type) We will access the Settings singleton via the shared static variable. Settings needs to conform to ObservableObject because the Picker will bind to the sortType property.

class Settings: ObservableObject {
    static let shared = Settings()
    @Published var sortType: SortType
    init() {
        sortType = .name
    }
}

For the UI, we will use the following Picker init

    public init(selection: Binding<SelectionValue>, label: Label, @ViewBuilder content: () -> Content)

The UI content view will start with something like this:

struct ContentView: View {
    @ObservedObject var settings = Settings.shared
    var body: some View {
        VStack {
            Picker(selection: $settings.sortType, label: Text("Sort Type")) {
                ForEach(SortType.allCases, id: \.self) { sortType in
                    Text("\(sortType.rawValue)")
                }
            }
            Text("sort type is: \(settings.sortType.rawValue)")
        }
    }
}

If we run this code, we’ll see a picker above a text label. When we pick a different value in the picker, the text label updates accordingly. Woot!

In Part 2, we will:

  1. Improve the UI by adding display names for the sort types
  2. Use UserDefaults to persist and recall the selected sort type
  3. Add another sort type
Categories
Uncategorized

Orca Overwhelms Otherwise Ordinary Outing

So yea, I saw an Orca this morning while biking along the sea wall in Stanley Park. It was quite a wonderful moment. I was clipping along with the wind at my back when I saw a black dorsal fin break the surface of the water under Lions Gate Bridge. Immediately and inelegantly, I stopped and got off my bike. Without consciously deciding, I just started walking back the direction I’d come from, to try and keep up with this whale. I was barely even aware of the fact that I was wearing my dorky bike shoes that are nearly impossible to walk in.

After walking alongside the whale for…. I don’t know how far exactly… maybe 60 metres, this lovely creature dove deeper and disappeared. A woman who had the presence of mind to record a video, said ‘He must be going to get some breakfast.’

As I clip clop walked back toward my bike, I was thinking about this happy connected feeling, and how it was strange that I felt so connected to this creature that I’m pretty sure had no idea I was appreciating it.

It was quite the magic moment.

On Orca just east of Lions Gate Bridge, heading into the inner harbour.

Update (9 June 2021): I reported my sighting to Ocean Wise Research, and they put a detailed post on Instagram.