It’s day 15 of the 100 Days of SwiftUI! After going through the first 14 days and learning the fundamentals of Swift, day 15 focused on recapping everything we’ve learned in rapid succession. Instead of going through everything we’ve learned again, like using optionals, I’ll be writing some examples on the subjects I’ve found difficult.
Ternary condition operator in SwiftUI
With the ternary conditional operator, we can quickly check a condition and put a resulting value in a variable. They follow the WTF acronym: what (condition), true (if the condition is true) and false (if the condition is false).
let age = 21
let canVote = age >= 18 ? "Yes" : "No"
print(canVote)
Closures
Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages.
The Swift Programming Language
let team = ["Darryl", "Jace", "Eliza", "Maine"]
var myTeam = team.filter({name in name.hasPrefix("E")})
print(myTeam)
Tomorrow, we’ll be starting our very first SwiftUI project. It’s time to recharge and get ready for a challenge, as the difficulty will ramp up from here. Onwards we go!
100 Days of SwiftUI – Day 15 – Consolidation