ios – Performance issue showing list of images from CoreData with SwiftUI from Xcode?


I have the following view:

import SwiftUI

struct ImagesView : View
{
    @Environment(\.managedObjectContext) private var objectContext
    @FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Photo.date, ascending: true)], animation: .default)
    private var photos: FetchedResults<Photo>

    @State private var gridHeight = 180.0

    var body: some View
    {
        VStack
        {
            ScrollView(.horizontal)
            {
                LazyHGrid(rows: [GridItem(.fixed(gridHeight))], alignment: .top, spacing: 0)
                {
                    ForEach(photos)
                    { photo in
                        if let data = photo.filteredData
                        {
                            Image(data: data)
                                .resizable()
                                .scaledToFit()
                        }
                    }
                }
                .frame(height: 200)
            }
        }
    }
}

When running this code on an iOS 16.x device all seems fine.
On an iOS 17.x device running from Xcode 15.2 however it takes quite long before the app becomes responsive. And, I see following message being printed when I open the tab this view is on and when scrolling through the images:

[0x10a022200] Created session
[0x10a025600] Created session
[0x10a028a00] Created session
[0x0] Releasing session
[0x0] Releasing session
[0x10612b600] Releasing session
[0x10a030200] Releasing session
[0x10a028a00] Releasing session
[0x10a022200] Releasing session
[0x0] Releasing session
[0x0] Releasing session
[0x106151c00] Created session
[0x10615bc00] Created session
[0x106151c00] Releasing session
[0x0] Releasing session
[0x10706da00] Created session
[0x107091800] Created session
[0x10706da00] Releasing session
[0x0] Releasing session
[0x10b858c00] Created session

When running the app on iOS 17.x device outside of Xcode, all is fine.

Is there a serious performance issue with the above code?
How could running from Xcode cause the long delays?
What could be causing these iOS logs?

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img