Michael Grant

Michael Grant

SwiftUI class notes 2021-11-25

Yes, even on Thanksgiving. (I suppose I should write something about how grateful I am to have the wherewithal to learn code, etc., and honestly I am, but I’m allergic to the orchestrated sentimentality that accompanies the fall and winter holidays.)


CaseIterable

/// A type that provides a collection of all of its values.
///
/// Types that conform to the `CaseIterable` protocol are typically
/// enumerations without associated values. When using a `CaseIterable` type,
/// you can access a collection of all of the type's cases by using the type's
/// `allCases` property.
///
/// The compiler can automatically provide an implementation of the
/// `CaseIterable` requirements for any enumeration without associated values
/// or `@available` attributes on its cases. The synthesized `allCases`
/// collection provides the cases in order of their declaration.

Dictionary of arrays

var categories: [String: [Landmark]] {
        Dictionary(
            grouping: landmarks,
            by: { $0.category.rawValue }
        )
    }