Loading a anchor using LoadAnchorAsync(contentsOf: URL) does not work. Here is my code:
if let url = url {
let loadRequest = Entity.loadAnchorAsync(contentsOf: url)
_ = loadRequest.sink(receiveCompletion: { completion in
// handle completion
}, receiveValue: { anchor in
self.arView.scene.addAnchor(anchor)
})
} else {
fatalError("no url")
}
but this crashes every time with an error:
Thread 27: EXC_BREAKPOINT (code=1, subcode=0x1051e0dfc)

Update: If i wrap the entire code block in an DispatchQueue.main.async block it doenst crash but neither reveiceCompletion or recieveValue gets called
You have to store subscriber somewhere in member
// somewhere above
private var subscribers: Set<AnyCancellable>()
...
if let url = url {
let loadRequest = Entity.loadAnchorAsync(contentsOf: url)
loadRequest.sink(receiveCompletion: { completion in
// handle completion
}, receiveValue: { anchor in
self.arView.scene.addAnchor(anchor)
}).store(in: &self.subscribers) // << keep it alive
} else {
fatalError("no url")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With