ios – SwiftUI View not Updating when an Array in a Class has up to date

Spread the love

Im having hassle getting the view to replace to mirror every new entityPosArray that’s handed in from a WebSocket reply.
It updates on this Class however not within the View, and I’m out of concepts to check.

I feel its across the line “entityPositionClassArray = entityPosArray” which isn’t registering as @ObservedObject replace?
It does work if I take advantage of a button motion to set off EntityPositions() however im after a stay view replace on every up to date Array handed in.

pattern entityPosArray:

[["EntID": "0012", "entPOSX": "1064.55", "entPOSY": "871.31"], 
["EntID": "5699", "entPOSX": "2231.13", "entPOSY": "1962.92"], 
["EntID": "5540", "entPOSX": "-1619.95", "entPOSY": "-1344.04"], 
["EntID": "5989", "entPOSY": "731.11", "entPOSX": "-1689.66"], 
["EntID": "0809", "entPOSX": "-971.65", "entPOSY": "-1761.38"]]

Up to now have simply been attempting to get the array.depend to replace within the view, after that the remainder needs to be simular.
I can see the info in console replace from the Class however don’t see a View reload or Textual content area replace.

import SwiftUI
import Mix
import Basis

class EntityPositionViewModel: ObservableObject {
    @Printed var entityPositionClassArray = [[String:String]]()
    @Printed var entityOnline: Int = 0
    func EntityPositions() {
        entityPositionClassArray = entityPosArray
        entityOnline = entityPositionClassArray.depend           // Added to check in console
        let _ = print("There are (entityOnline) linked")    // <- This works on every Array replace

struct EntityOnline: View {
    @ObservedObject var mannequin = EntityPositionViewModel()
    init() {
        mannequin.EntityPositions()                 // init() makes no distinction
    var physique: some View {
        VStack {
            Textual content("Take a look at: (mannequin.entityOnline)")
            // Testing for View Replace and Reload
            let entityOnline2 = mannequin.entityPositionClassArray.depend // Checking totally different name
            let _ = print("TestEnts: (entityOnline2)")
            let _ = print("View Reloaded")

Leave a Reply

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