Skip to content

Instantly share code, notes, and snippets.

View nataliapanferova's full-sized avatar

Natalia Panferova nataliapanferova

View GitHub Profile
// 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
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")]