V8tr / AsyncImage

Asynchronous Image Loading from URL in SwiftUI
https://www.vadimbulavin.com/
The Unlicense
274 stars 36 forks source link

Crash during runtime with XCode beta 2 and iOS14 beta #8

Closed nacohen closed 4 years ago

nacohen commented 4 years ago

The final version of the app crashed for me under iOS14 beta and XCode beta 2 during runtime, when the loader ObservedObject in AsyncImage underwent a premature deinit() during a view update when the downloaded images began to be displayed.

The fix was to make loader an @StateObject to allow it to persist during view updates. To initialize load in AsyncImage's init() required this line of code:

_loader = StateObject(wrappedValue: ImageLoader(url: url, cache: cache))

tatealive commented 4 years ago

@nacohen I think I am experiencing this issue with iOS 14 as well - can you show me how you converted it to a StateObject?

tatealive commented 4 years ago

@V8tr I also experience a crash on iOS 14 when AsyncImage is embedded in a List.

Fix was a combination of nacohen's conversion to StateObject to ensure that caching worked properly, and also changing AsyncImage.swift line 29 from 'Group' to 'VStack' to avoid crashes

V8tr commented 4 years ago

Hi guys, I've updated the project for iOS 14 and now using StateObject instead of ObservedObject. This solved the crash.