I am getting the next error:
[Amplify] Name
fetchto lazy load the listing earlier than accessing
parts. Amplify/Checklist+Mannequin.swift:47: Deadly error: Name
fetchto lazy load the listing earlier than accessing
parts.
My code:
func queryAlbums() {
Job {
do {
let end result = strive await Amplify.API.question(request: .listing(AlbumData.self))
swap end result {
case .success(let albumData):
print("Efficiently retrieved listing of Albums")
// Convert an array of AlbumData to an array of Album class situations
for a in albumData {
let album = Album.init(from: a)
// Fetch the listing of photographs for the album
do {
let photographs = strive await fetchPhotosForAlbum(albumId: a.id)
album.photographs = photographs.map { Photograph(from: $0) }
} catch {
print("Error fetching photographs for album: (a.identify)")
}
await MainActor.run {
UserData.shared.albums.append(album)
}
}
case .failure(let error):
print("Can not retrieve end result: error (error.errorDescription)")
}
} catch {
print("Can not retrieve Albums: error (error)")
}
}
}
Higher related portion of my AlbumData Mannequin:
public let id: String
public var identify: String
public var coverPhotoId: PhotoData?
public var photographs: Checklist<PhotoData>?
public var createdAt: Temporal.DateTime?
public var updatedAt: Temporal.DateTime?
public var albumDataCoverPhotoIdId: String?
Higher related portion of my PhotoData Mannequin:
public let id: String
public var picture: String
public var albumdataID: String
public var isCoverPhoto: Bool?
public var createdAt: Temporal.DateTime?
public var updatedAt: Temporal.DateTime?
func fetchPhotosForAlbum(albumId: String) async throws -> [PhotoData] {
let photosData = strive await Amplify.API.question(request: .listing(PhotoData.self, the place: PhotoData.keys.albumdataID == albumId))
swap photosData {
case .success(let photosList):
strive await photosList.fetch()
return photosList.parts
case .failure(let error):
print("Failure")
throw error
}
}
I am very new to Swift App improvement and I have been engaged on studying and understanding it higher. Nevertheless, I hold getting the above error and I simply cannot appear to determine why that is taking place. Once I run the simulator, it simply crashes with that error. Proper now I’ve two GraphQL tables; PhotoData and AlbumData.
I used to be in a position to create the album simply advantageous. Nevertheless, after doing so, once I open the app again up it simply crashes. Proper now there’s an album created, however no photos are assigned to it but. From what I can inform, it’s making an attempt to entry the picture listing earlier than it’s accessible. That is my greatest visitor.
Can any professional’s on the market assist me type this out?