iOS Development

ios – Calling objectWillChange.ship() produce efficiency points

I’ve a venture with a nested object construction

Venture -> Panels -> Layers

and I’ve SettingsView the place I replace totally different properties of any of those constructions.

On each replace I’ve to name objectWillChange.ship() to see adjustments in View instantly.
If I’ve a small variety of objects it really works superb and produces no efficiency points. But when the variety of objects will increase it makes perf points.

Instance of my code beneath:

class SelectedProjectHolder: ObservableObject {
    @Printed var tasks: [Project] = []
    @Printed var selectedProject: Venture? = nil
.....
    func updateTextLayerColor(for textLayer: TextLayer, newColor: Colour) {
        guard let selectedProject = selectedProject else {
            return
        }
        
        for (panelIndex, panel) in selectedProject.panels.enumerated() {
            if let layerIndex = panel.textLayers.firstIndex(the place: { $0.id == textLayer.id }) {
                selectedProject.panels[panelIndex].textLayers[layerIndex].shade = newColor
                objectWillChange.ship()
                return
            }
        }
    }
....
}

struct MainApp: App {
    
    let selectedProjectHolder = SelectedProjectHolder()
var physique: some Scene {
        WindowGroup {
            ContentView(lastSaveTime: lastSaveTime)
                .environmentObject(selectedProjectHolder)
        }
        .instructions {
            SidebarCommands()
        }
    }
}

What do I miss and why it does not work with out calling objectWillChange.ship() explicitly?

Is there a strategy to see adjustments instantly with out calling objectWillChange.ship() each time I make adjustments in selectedProject property of SelectedProjectHolder?

Credit: www.ismmailgsm.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button