Post

Replies

Boosts

Views

Activity

Reply to RealityView annotations not updating
Okay, I've figured out a few things here, in case someone has similar issues: I was holding it wrong in that there was an issue with changes not being picked up by the binding. After I fixed that, the attachments: handler did get called again. Hooray. The old AttachmentView did stick around though, due to the IDs of my attachments changing when they changed shape. I fixed this by making sure those IDs are stable, and calling content.add(...) again in the update: handler then updated those to the new look. The remaining issues was to get rid of all attachment entities if they disappear from my Binding. I'm not particularly happy with it, but the solution I came up with, was to collect the IDs and then iterate through all entities to check if their IDs are still in my set: let allEntities = Array(content.entities) for entity in allEntities { if let attachmentEntity = entity as? ViewAttachmentEntity, let id = attachmentEntity.attachment.id as? String, !goodIDs.contains(id) { content.remove(attachmentEntity) } } Would love to know if there's a better way to do this.
Jun ’23
Reply to CoreData CloudKit sync resulting in main thread initialisation issue
It appears that the reason is that I'm using the SwiftUI App model for my Mac app, and the init() method of my App subclass is not running via NSApplicationMain. So if other code, such as CloudKit then runs it'll assign the main thread to the wrong queue or thread. I can fix this manually by calling let _ = NSApplication.shared manually in my init() method or by deferring my access to CloudKit / CoreData using DispatchQueue.main.async { ... } calls. Submitted as FB10902789, as a SwiftUI bug.
Jul ’22