@julia_brockovich Thanks for the reply! I did try your suggestion, but onMove seems to mostly be for rearranging list items. What I need is a little more complex than that. I need to be able to know that the what the user dragged and what was dragged onto. onMove does give me the indices as closure variables after the user has released the list element, so I could theoretically get something going, but I don't think it would make for the best user experience, compared to using the onDrop APIs.
Post
Replies
Boosts
Views
Activity
@Developer Tools Engineer Wow thanks. I feel like an ***** 😂. I didn't even think about the possibility of Xcode not updating automatically since I didn't get it from the App Store.
In case anyone else is having a similar issue as I am, I have managed to solve it. I still do not know the cause, so I went ahead and filed a bug report, but I do know the fix. Do not fret, I will not leave you in the dark for when you inevitably stumble upon this in ten years time just to see "Solved it!".
As much as I would like to take credit for it, credit should actually go to @timbretimbre on StackOverflow for his superb recommendation to streamline my code. Here's the link to the original question just for thoroughness' sake: https://stackoverflow.com/questions/76524832/image-view-is-rendering-in-xcode-preview-but-not-on-device
First, I completely deleted the "@State var image" variable at the top. Next, in the ImageLoader class, replace the data variable with a normal, @Published variable and initialize it to a Data() object. Basically, just delete the didSet code block and add @Published. And then finally, remove the .onReceive bit from the Image view up top and set the uiImage attribute of the Image View to "UIImage(data: imageLoader.data)!"
Here's a summary:
Remove the "image" variable:
struct ImageView: View {
@ObservedObject var imageLoader: ImageLoader
init(withUrl url: String) {
imageLoader = ImageLoader(urlString: url)
}
Refactor the data variable inside the ImageLoader class:
class ImageLoader: ObservableObject {
var didChange = PassthroughSubject<Data, Never>()
@Published var data = Data()
Refactor the Image View:
Image(uiImage: UIImage(data: imageLoader.data)!)
.resizable()
.aspectRatio(contentMode: .fit)
Hope this helps someone!