Read Clean Up Your Sheet API.

Read The Simple Life(cycle) of a SwiftUI View in 2025.

Read apple documentation Migrating to the SwiftUI life cycle.

Hm, what’s Task<CGImage, Never> in Swift Concurrency: Keeping Completed Tasks as Cache Objects??

actor ImageLoader
{
    private var activeTasks: [URL: Task<CGImage, Never>]

    // Construct a single image
    private func perform(with url: URL) async -> CGImage
    {
        // Fetch URL data, generate CGImage, etc. Ignore errors for brevity.
    }


    // Retrieve a single image from the cache, if possible, or create a new Task if needed.
    func image(for url: URL) async -> CGImage
    {
        if let task = activeTasks[url] 
        {
            // If the task has already finished, this returns immediately.
            return await task.value
        }
        else
        {
            let task = Task<CGImage, Never> {
                return await perform(with: url)
            }
            activeTasks[url] = task
        }
    }
}