Reputation: 2678
I have an app that has to show multiple images that are large in dimension, which can use up lots of memory.
I'm only familiar with SwiftUI and don't have much experience using UIKit, but according to this WWDC's iOS Memory Deep Dive presentation: there are multiple ways you can reduce memory usage when rendering images in UIKit.
Its possible because rendering images in UIKit takes multiple steps which allows more room for modifications and gives you more flexibility, but in SwiftUI, it's so simple there is not as much room for modifications:
Image("image name")
.resizable()
.frame(width:100,height:100)
So does SwiftUI already optimized the image's dimensions and color space with the above code, or is it more memory efficient to use UIKit to optimize the image, then pass the optimized UIImage
to SwiftUI for viewing?
Is using UIImages
rendered (and optimized) from UIKit for image viewing SwiftUI overall a better practice than just using Image("image name")
?
Any answer would be appreciated.
Upvotes: 0
Views: 251
Reputation: 17544
You can use any of
init(nsImage: NSImage)
or
init(uiImage: UIImage)
to take advantage of all knowledge you already have from UIKit or AppKit
Upvotes: 1