revidwerd

Day 11 of #100DaysOfSwiftUI was all about protocols, extensions and protocol-oriented programming (POP).

David Abrahams via his talk at WWDC:

So, yes, Swift is great for object-oriented programming, but from the way for loops and string literals work to the emphasis in the standard library on generics, at its heart, Swift is protocol-oriented.

Day 10 of #100DaysOfSwiftUI was all about classes, inheritance, overriding (also blocking this via final), mutability and the differences between structs and classes. Important note:

SwiftUI uses structs extensively for its UI design. Well, it uses classes extensively for its data: when you show data from some object on the screen, or when you pass data between your layouts, you’ll usually be using classes.

Day 9 of #100DaysOfSwiftUI was all about structs (creating custom data types) and utilizing initializers as well as static and “lazy” properties.

Day 8 of #100DaysOfSwiftUI was all about structs, methods, mutability and finished with demoing how array and string types are structs and have their own methods which can be called to sort, append, etc.

Day 7 of #100DaysOfSwiftUI was closures part 2, this link will come in handy.

Revisiting Day 6 of #100DaysOfSwiftUI to truly ensure I get the basics down…

I spent most of the weekend in review (see the previous post with a link to the iOS app)

Day 6 of #100DaysOfSwiftUI was an ease into the idea of closures. Though my head was a bit achy at first, I faired pretty well on each sections quiz. In order to somewhat solidify, one always calls paramaters after the first { and you always call the closure that accepts a parameter without the parameter label.

let myAcceptingClosure = { (something: String) in 
    print("I'm a closure that accepts a parameter, such as \(something)...")
}

// We call this WITHOUT the label
myAcceptingClosure("This")

End of week #100DaysOfSwiftUI progress 🤘🏼

I’m on level 11 in Unwrap by @twostraws. Download it here: itunes.apple.com/app/id144…

Day 5 of #100DaysOfSwiftUI was all about functions and their various incantations. This included returning values (tuples are great for returning more than 1 valule!), accepting parameters, labeling parameters for better legibility (omitting labels in some cases), setting default parameters, “inout” parameters, “throwing functions,” and variadic functions (passing in 0 or more values).

Ternary operators shine in SwiftUI as it uses single expression functions quite a bit:

func greet(name: String) -> String {
        name == "Drew Diver" ? "My liege..." : "Hello, \(name)! Back of the line!"
}

Parameter labels make function calls read naturally:

func sayHello(to name: String) {
        print("Hello, \(name)!")
}

sayHello(to: "Drew Diver”)

Omitting parameter labels makes sense in cases like the following:

func read(_ book: String) {
        print("Now reading \(book)...")
}

read("Walden")

Also In Objective-C:

…the first parameter to a function was always left unnamed, and so when you use those frameworks in Swift you’ll see lots of functions that have underscores for their first parameter label to preserve interoperability with Objective-C.

Day 4 of #100DaysOfSwiftUI was all about looping and included while, for, repeat. We then went within loops to apply continue (to skip) and/or break statements to exit. break can be combined with labeling the outermost loop to ensure we exit both loops like so:

outermost: for i in 1...10 {
    for j in 1...10 {
        let total = i * j
        print("\(i) * \(j) = \(total)")
        if total == 100 {
            print("That's enough!")
            break outermost
        }
    }
}

Day 3 of #100DaysOfSwiftUI included operators, compounds (+= or -= for instance), comparisons, switch statements, ternary and ranges!

I kind of like the look of ternary vs if blocks but I guess time and experience in Swift will tell…

var firstCard = 11
var secondCard = 10
print(firstCard + secondCard == 21 ? “Blackjack!” : “Regular cards”)

Day 2 of #100DaysOfSwiftUI was about complex data types such as Arrays, Dictionaries, Tuples, Sets and Enums (including the use of Raw Values and Associated Values).

Doubling down on my efforts to get a grasp of Swift and SwiftUI this year… I just completed day 1 of #100DaysOfSwiftUI. This lesson introduced variables, integers, doubles, strings (interpolation / multi-line), boolean, constants and type declarations.