How to add a flag to existing ARAnchor classes in Swift?

Been programming a long tiime but still getting used to swift.

What I need to do is add a has_been_updated flag to all my ARAnchors that can be set by the didUpdate delegate and later cleared by something else.

Not sure of the correct way to do this, if it can be done with extensions and how to apply it to all ARAnchors.

The application, I am sending the ARKit anchor data over UDP to an external (non Apple) device on another computer. Because ARKit updates anchor data very frequently, I want to mark the data as "has been updated" when I get a didUpdate event and then every few seconds iterate over all the anchors and only send the ones that have been updated. This reduces data a lot because in the course of a second something like a meshAnchor might update 10 times.

What would be the appropriate way to add this flag to the ARAnchor class in Swift?

You could maintain your own set which contains the IDs of all anchors which have been updated since the last check. Something like:

    var session: ARSession?
    var updatedAnchorIDs: Set<UUID> = []

    func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) {
        for updatedAnchor in anchors {
            updatedAnchorIDs.insert(updatedAnchor.identifier)
        }
    }

    func sendUpdatedAnchorsViaUDP() {
        guard let currentFrame = session?.currentFrame else { return }

        var anchorsToSend: [ARAnchor] = []

        for anchor in currentFrame.anchors {
            if updatedAnchorIDs.contains(anchor.identifier) {
                anchorsToSend.append(anchor)
            }
        }

        // Clear the set
        updatedAnchorIDs = []

        // Send the updated anchors via UDP...
    }
How to add a flag to existing ARAnchor classes in Swift?
 
 
Q