I’ve been utilizing AsyncImage for my venture which will get the photographs utilizing urls. I assumed AsyncImage is one of the simplest ways to go since SwiftUI offers a prepared to make use of part for it.
Nevertheless, if a picture load fails, then I get a typical error and never an in depth error message of why the url request failed (eg: no permissions to entry URL or another purpose).
The rationale I’m always seeing is The operation couldn’t be accomplished. (SwiftUI.(unknown context at $1d2600574).LoadingError error 1.)
Executable code:
import SwiftUI
class Foo {
var title: String
var url: String
var picture: Picture?
init(title: String, url: String, picture: Picture? = nil) {
self.title = title
self.url = url
self.picture = picture
}
}
struct ContentViewA: View {
@State var showSheetA: Bool = false
var physique: some View {
VStack {
Textual content("That is major view")
}
.onAppear{
showSheetA = true
}
.sheet(isPresented: $showSheetA) {
SheetViewA()
}
}
}
struct SheetViewA: View {
@State var information = [
Foo(title: "Image E", url: "https://t3.ftcdn.net/jpg/10/08/34/50/360_F_1008345045_VOe4ziz83vb6d3E3X6KI00qHyLd32D4l.jpg123", image: nil)
]
@State var panelDetent: PresentationDetent = .medium
var physique: some View {
NavigationStack {
VStack {
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .heart, spacing: 10) {
ForEach(information, id: .title) { merchandise in
if let urlObject = URL(string: merchandise.url) {
AsyncImage(url: urlObject,
scale: 1.0,
transaction: Transaction(animation: .spring(response: 0.5, dampingFraction: 0.65, blendDuration: 0.025)),
content material: { renderPhoto(section: $0, merchandise: merchandise) })
} else {
/// Word: Exhibits placeholder view
EmptyView()
}
}
}
.background(Shade.grey.opacity(0.2))
.padding(.main, 0)
.padding(.trailing, 16)
.body(maxWidth: .infinity, minHeight: 65, maxHeight: 65, alignment: .topLeading)
}
}
.padding([.top, .bottom], 150.0)
.presentationDetents([.medium, .large], choice: $panelDetent)
}
}
@ViewBuilder
personal func renderPhoto(section: AsyncImagePhase, merchandise: Foo) -> some View {
swap section {
case .success(let picture):
let _ = print("Success state")
case .failure(let error):
let _ = print("%%% detailed error is - (error.localizedDescription) %%%%")
case .empty:
let _ = print("Empty state")
@unknown default:
EmptyView()
}
}
}
Is there a approach to get detailed error message utilizing AsycnImage? Or will I’ve to get photographs utilizing the outdated URLSession request methodology? I must show detailed error message on the UI.