Итак, у меня есть два быстрых экрана (Screen1) и Screen1Details, поэтому моя проблема заключается в получении данных, отправленных с Screen1 в Screen1Details, и передаче их по URL-адресу, который загружает мой файл JSON.
Пока я могу читать эти данные, отправленные с экрана 1, но я не могу добавить их к URL, который загружает мой JSON
Вот мой код
* ** Screen1
NavigationView {
VStack {
List(fetcher.guidelines) { row in
NavigationLink(destination: Chapters(sentGuidelineId: row.id)){
......
}
}
.navigationBarTitle(Text("Some title"))
}
}
*** Screen1Details
import SwiftUI
struct Chapters: View {
let sentGuidelineId: String
@ObservedObject var cfetcher = ChaptersFetcher()
var body: some View {
NavigationView {
some code .....
}
}
}
struct Chapters_Previews: PreviewProvider { static var previews: some View {
Chapters()
}
}
public class ChaptersFetcher: ObservableObject {
@Published var chapters = [Chapter]()
let url = URL(string: "https://myurl/api/get_screen1data.php?GuidelineId=\(sentGuidelineId)")! // My issue is here, i cant read the passed data here
init(){
load()
}
func load() {
URLSession.shared.dataTask(with: url) {(data,response,error) in
do {
if let d = data {
let decodedLists = try JSONDecoder().decode([Chapter].self, from: d)
DispatchQueue.main.async {
self.chapters = decodedLists
}
}else {
print("No Data found")
}
} catch {
print ("Error loading data \(error)")
}
}.resume()
}
}
struct Chapter: Codable, Identifiable {
//public var error: Bool
public var id: String
public var name: String
public var descriptions: String
public var parentId: String
public var contentLevelId: String
public var order: String
enum CodingKeys: String, CodingKey {
//case error = "error"
case id = "Id"
case name = "ChapterName"
case descriptions = "Descriptions"
case parentId = "ParentId"
case contentLevelId = "ContentLevelId"
case order = "Order"
}
}