This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1. - Iterate over items and indices in collections | |
| var ingredients = ["potatoes", "cheese", "cream"] | |
| for (i, ingredient) in ingredients.enumerated() { | |
| // The counter helps us display the sequence number, not the index | |
| print("ingredient number \(i + 1) is \(ingredient)") | |
| } | |
| // Array<String>.SubSequence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct Item: Identifiable { | |
| let id = UUID() | |
| let name: String | |
| } | |
| struct ContentView: View { | |
| @State private var items = [Item(name: "Item 1"), Item(name: "Item 2"), Item(name: "Item 2")] |