27 - SwiftData
Guard
guard container != nil else {
fatalError("This view needs a persistent container.")
}
// container is accessible here!
...
The unwrapping is a little unintuitive with guard - if let unwraps values for use inside a block. Here the guard statement has an associated block but it’s actually an else block - i.e., the thing you do if the unwrapping fails - the values are unwrapped straight into the same context as the statement itself.
Same as TypeScript/C# compiler analysis
if (!thingMaybeNull) return;
thingMaybeNull.nowItIsNotNull();
Extension
extension ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView,
canEditRowAt indexPath: IndexPath) -> Bool {