Memorise Assignment 1

28 July 2022

A small milestone achieved - I’ve completed the first assignment from the CS193p lecture series - some minor changes to the app being built in the lectures. There was a couple of things I was unhappy with:

    let animalEmojis = ["🐠", "🐢", "🦋", "🐥", "🐣", "🐰", "🐝", "🦄", "🐵", "🐛"]
    let weatherEmojis = ["🌪", "🌝", "🌈", "🔥", "🌧", "🌙", "🌬", "☃️", "☔️", "🌫"]
    let transportEmojis = ["🚗", "🚕", "🚲", "🚚", "🛵", "🚜", "🛴", "🛺", "🚃", "🚡"]

    // I'm not happy with this duplication //TODO
    @State var emojis = ["🐠", "🐢", "🦋", "🐥", "🐣", "🐰", "🐝", "🦄", "🐵", "🐛"]

This second problem is because I couldn’t just

@State var emojis = animalEmojis

When I tried it, I encountered the error:

Cannot use instance member 'animalEmojis' within property initializer; property initializers run before 'self' is available

This is vexing - the constants are defined on the lines above, so surely if this property exists, the ones before it do. Apparently that can’t be depended on - probably for some good reason that will be unveiled at some stage. It’s not because emojis is wrapped in the @State which probably does cause the variable to be created off somewhere else - I tried with just an ordinary var and had the same issue.

Then I read further down into the assignment, there’s a “hints section” which I should clearly be reading before I being. C’s get degrees.

Message received. Don’t worry about the doubled up string array, and go back and watch the lecture again. There was something about locking an aspect ratio for an SF Symbol at some stage.