Skip to content

Instantly share code, notes, and snippets.

@ashishkakkad8
Created August 21, 2022 12:56
Show Gist options
  • Save ashishkakkad8/26f80302de1595a588ae51c10026d22e to your computer and use it in GitHub Desktop.
Save ashishkakkad8/26f80302de1595a588ae51c10026d22e to your computer and use it in GitHub Desktop.
Populate Contact List in SwiftUI
//
// ContactListView.swift
// APISwiftUI
//
// Created by Kode on 21/08/22.
//
import SwiftUI
struct ContactListView: View {
@State var arrData = [Contact]()
var body: some View {
NavigationView {
List(arrData) { data in
VStack(alignment: .leading) {
Text("\(data.name ?? "")")
Text("\(data.email ?? "")")
}
}
.onAppear() {
APIHelper().loadData { (result) in
self.arrData = result.contacts ?? []
}
}.navigationTitle("List")
}
}
}
struct ContactListView_Previews: PreviewProvider {
static var previews: some View {
ContactListView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment