please help, i am new to SWIFTUI getting an error: A NavigationLink is presenting a value of type “String” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated.
struct debug_navigation_3: View {
@State private var path = NavigationPath()
@StateObject private var debug_Client_Lead_Data_ListVM = Debug_Client_Lead_Data_List_Model()
var body: some View {
NavigationStack(path:$path) {
VStack {
List(debug_Client_Lead_Data_ListVM.Debug_Client_Lead_Data_Rows, id: \.self) { curr_clientLeadRequest in
NavigationLink(curr_clientLeadRequest.Client_Message, value: curr_clientLeadRequest.Client_Message)
}
}
.navigationDestination(for:Debug_Client_Lead_Data.self) { curr_clientLeadRequest in
debug_navigation_3_DetailView(rec_id: Int64(curr_clientLeadRequest.id))
}
}
.onAppear() {
Task {
await debug_Client_Lead_Data_ListVM.search(rec_id:Int64(0)) //bring all REST API
}
}
}
}
// data model
import Foundation
struct Debug_Client_Lead_Data_Response: Decodable {
let Debug_Client_Lead_Data_Rows: [Debug_Client_Lead_Data]
private enum CodingKeys: String, CodingKey {
case Debug_Client_Lead_Data_Rows = "rows" // root tag: REST API
}
}
struct Debug_Client_Lead_Data: Decodable, Hashable, Identifiable {
let id:Int32
let Client_Message: String
private enum CodingKeys: String, CodingKey {
case id = "id"
case Client_Message = "Client_Message"
}
}
//list view model
import Foundation
@MainActor
class Debug_Client_Lead_Data_List_Model: ObservableObject {
@Published var Debug_Client_Lead_Data_Rows: [Debug_Client_Lead_Data_ListViewModel] = []
func search(rec_id:Int64) async {
do {
let Debug_Client_Lead_Data_Rows =
try await Webservice_debug_client_lead_data().getClientLeadRequestSummary(rec_id:rec_id) // '0' optional
self.Debug_Client_Lead_Data_Rows = Debug_Client_Lead_Data_Rows.map(Debug_Client_Lead_Data_ListViewModel.init)
} catch {
print(error)
}
}
}
struct Debug_Client_Lead_Data_ListViewModel: Identifiable, Hashable {
let debug_Client_Lead_Data: Debug_Client_Lead_Data
var id:Int32 {
debug_Client_Lead_Data.id
}
var Client_Message: String {
debug_Client_Lead_Data.Client_Message
}
}
//REST API
import Foundation
class Webservice_debug_client_lead_data {
func getClientLeadRequestSummary(rec_id:Int64) async throws -> [Debug_Client_Lead_Data] {
var components = URLComponents()
components.scheme = Global_REST_API_URL_HTTP
components.host = Global_REST_API_URL
components.port = Global_REST_API_URL_port
components.path = "/GetClientLeadRequest"
components.queryItems = [
URLQueryItem(name: "rec_id", value: String(rec_id)) // Optional, pass '0' for all rows
]
guard let url = components.url else { throw NetworkError.badURL }
let (data, response) = try await URLSession.shared.data(from: url)
guard (response as? HTTPURLResponse)?.statusCode == 200 else {throw NetworkError.badID }
let Debug_Client_Lead_Data_Response = try? JSONDecoder().decode(Debug_Client_Lead_Data_Response.self, from: data)
return Debug_Client_Lead_Data_Response?.Debug_Client_Lead_Data_Rows ?? []
}
}