Created
August 21, 2022 12:56
-
-
Save ashishkakkad8/26f80302de1595a588ae51c10026d22e to your computer and use it in GitHub Desktop.
Populate Contact List in SwiftUI
This file contains 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
// | |
// 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