Has the issue resolved? I convert a UIimage to data by the following codes, and save it to swiftData. But I get nil when I read it. Why?
//save photo with swiftData
let cameraPhotoID = UUID().uuidString
let image = camera.photo.image!
let data = image.pngData()
let CameraPhoto = cameraPhoto(cameraPhotoID: cameraPhotoID,cameraPhotoData: data!)
modelContext.insert(CameraPhoto)
try? modelContext.save()
Post
Replies
Boosts
Views
Activity
Yes, it's SwiftUI app.
After trying several times, I found the bug is related with @EnvironmentObject var. If I change $userViewModel.focusTime(which is an EnvironmentObject var) to focusTime(which is a @State var), the view works well. There is no any issue. But when I change the variable back to the @EnvironmentObject var, the same bug appears. But the data type is the same between both of them.