Learning Swift - Day Three

Done

The Goal

Today is day 3 of learning Swift. After finishing the first documentation book on the basics of Swift I’m going to now focus on watching another Stanford leacture - https://www.youtube.com/watch?v=IvOF3Bmk-94&list=PLoROMvodv4rPHblRXKsJCQs8TLGpiCTrG&index=4.


Notes from leacture

Button("Add item") {
    withAnimation{
        addItemFunc()
    }
}
enum Kind: Equatable {
    case master
    case guess
    case attempt([Match]) // An array is equatable and then the things inside the array must also be equatable.
    case unknown
}

// If we didn't have `Equatable` then we wouldn't be able to do this check.
if fake.kind === .attempt {
    // do something
}
static func == (lhs: Kind, rhs: Kind) -> Bool {
    switch { ... }
}
Image("photo")
    .overlay(
        Text("NEW")
            .padding(4)
            .background(.red),
        alignment: .topTrailing
    )

// Or another common one is adding a border with rounded corners, since .border doesn't follow a clipped shape
RoundedRectangle(cornerRadius: 12)
    .fill(.gray.opacity(0.2))
    .overlay(
        RoundedRectangle(cornerRadius: 12)
            .stroke(.blue, lineWidth: 2)
    )
Text("A long piece of text that might not fit")
    .minimumScaleFactor(0.5)  // can shrink to 50% of the font size