前提
作成したAPIでDBからデータを取得しています。
idについては取得したuuidでと考えています。
APIは一覧取得、詳細取得の二つ用意しています。
実現したいこと
リストで表示している項目の詳細画面への遷移
発生している問題・エラーメッセージ
Cannot convert value of type 'ContactListView.ContactResult' to expected argument type 'ContactResult' Incorrect argument label in call (have 'contact:', expected 'item:') Replace 'contact' with 'item'
該当のソースコード
Swift
1#一覧画面 2struct ContactListView: View { 3 4 @State private var contact = [ContactResult]() 5 6 var body: some View { 7 8 NavigationView{ 9 List{ 10 ForEach(contact, id: \.contact_id) { item in 11 NavigationLink(destination: ContactView(contact: item)){ 12 VStack{ 13 Text(item.last_name) 14 Text(item.last_name_kana) 15 Text(item.first_name) 16 Text(item.first_name_kana) 17 } 18 }
Swift
1#一覧画面用 2 struct ContactsResponse: Codable { 3 var status: Bool 4 var result: ContactsResult 5 } 6 7 struct ContactsResult: Codable { 8 var contacts: [ContactResult] 9 } 10 11 struct ContactResult: Codable { 12 var contact_id: UUID 13 var first_name: String 14 var first_name_kana: String 15 var last_name: String 16 var last_name_kana: String 17 }
Swift
1#詳細画面 2struct ContactView: View { 3 var item: ContactResult 4 5 var body: some View { 6 VStack { 7 AsyncImage(url: URL(string: item.contact_image ?? "")){ image in 8 image.resizable() 9 } placeholder: { 10 ProgressView() 11 } 12 .frame(width: 50, height: 50) 13 Group { 14 Text(item.first_name) 15 Text(item.first_name_kana) 16 Text(item.last_name) 17 Text(item.last_name_kana) 18 Text(item.email1 ?? "") 19 Text(item.email2 ?? "") 20 Text(item.tel1 ?? "") 21 Text(item.tel2 ?? "") 22 Text(item.company ?? "") 23 Text(item.address ?? "") 24 }
Swift
1#詳細画面用 2struct ContactResponse: Codable { 3 var status: Bool 4 var result: ContactResult 5} 6 7struct ContactResult: Codable { 8 var contact_image: String? 9 var contact_id: UUID 10 var first_name: String 11 var first_name_kana: String 12 var last_name: String 13 var last_name_kana: String 14 var email1: String? 15 var email2: String? 16 var tel1: String? 17 var tel2: String? 18 var company: String? 19 var address: String? 20}
試したこと
ネットで探してみましたが参考になりそうなものを見つけられず
補足情報(FW/ツールのバージョンなど)
初学者で不明な点も多くご教授いただきたく
あなたの回答
tips
プレビュー