Skip to content

Displaying a List in SwiftUI

   

Here's how to display a list in SwiftUI. Since this is the screen after the screen transition, there is a NavigationBar.

SwiftUI List

import SwiftUI
struct Fruit: Identifiable {
var id: Int
let name: String
}
struct ContentView: View {
let fruits: [Fruit] = [
Fruit(id: 0, name: "Apple"),
Fruit(id: 1, name: "Banana"),
Fruit(id: 2, name: "Orange"),
Fruit(id: 3, name: "Grape"),
Fruit(id: 4, name: "WaterMelon"),
]
var body: some View {
VStack {
Divider()
List (fruits) { fruit in
Text(fruit.name)
}
.edgesIgnoringSafeArea([.bottom])
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

  1. Sending push notifications to your app with cURL (curl)
  2. Retrieving a certificate and private key from a P12 file
  3. Update cocoapods installed with gem.
  4. I had a chance to speak at iOSDCJapan2019 Day 1 in the Rookies LT slot.
  5. Changing the height of a TableView cell (Swift5.0.1)
  6. UIButton, display a button (Swift5.0)
  7. Using UISlider to retrieve a value at regular intervals (Swift5.0)