Skip to content

Transition from one ListView to another (SwiftUI)

   

It was a bit of a hassle to transition from one ListView to another like the configuration screen.
I feel like there's a better way to do it.

ListView to AnyView

import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Divider()
List (samples) { sample in
self.containedView(sample: sample)
}
.edgesIgnoringSafeArea([.bottom])
}
}
}
func containedView(sample: Sample) -> AnyView {
switch sample.view {
case .view_20191030: return AnyView(NavigationLink (destination: List_20191030()) {
Text(sample.title)
})
case .view_20191111: return AnyView(NavigationLink (destination: Tutorial_20191111()) {
Text(sample.title)
})
case .view_20191114: return AnyView(NavigationLink (destination: ContentView_20191114()) {
Text(sample.title)
})
case .view_20191120: return AnyView(NavigationLink (destination: ContentView_20191120()) {
Text(sample.title)
})
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
import SwiftUI
struct Sample: Identifiable {
var id: Int
var title: String
var view: ViewEnum
}
enum ViewEnum {
case view_20191120
case view_20191114
case view_20191111
case view_20191030
}
let samples: [Sample] = [
Sample(id: 20191120, title: "TabView", view: .view_20191120),
Sample(id: 20191114, title: "Make Unique Value", view: .view_20191114),
Sample(id: 20191111, title: "Tutorial (Creating and Combining Views)", view: .view_20191111),
Sample(id: 20191030, title: "List (SwiftUI)", view: .view_20191030)
]
view raw Samples.swift hosted with ❤ by GitHub

  1. Parsing the Json received in Alamofire using Codable
  2. SwiftUI gets used a lot with Struct
  3. Displaying a List in SwiftUI
  4. Sending push notifications to your app with cURL (curl)
  5. Retrieving a certificate and private key from a P12 file
  6. Update cocoapods installed with gem.
  7. I had a chance to speak at iOSDCJapan2019 Day 1 in the Rookies LT slot.