google-ar / arcore-ios-sdk

ARCore SDK for iOS
https://developers.google.com/ar/
Apache License 2.0
282 stars 84 forks source link

Issue attempting to implement GARSessionDelegate in Swift #61

Open kv-jw opened 2 years ago

kv-jw commented 2 years ago

Hi all,

I'm attempting to use the latest release of the sdk in Swift, working with cloud anchors. When attempting to extend my anchor manager class and inherit from the GARSessionDelegate class, I get the following warning from Xcode:

Cannot declare conformance to 'NSObjectProtocol' in Swift; 'CloudAnchorManager' should inherit 'NSObject' instead

The only fix in this situation, to my knowledge, would be to implement the missing methods from the NSObjectProtocol. Is this intended functionality, or am I using this improperly? My current implementation looks like this:

extension CloudAnchorManager: GARSessionDelegate {

    func session(_ session: GARSession, didHost anchor: GARAnchor) {
        print("Anchor hosted successfully. Cloud ID: \(anchor.cloudIdentifier)")

        // Do something with hosted anchor here
    }
}

Would appreciate any feedback or insight with this, thanks!

jrullman commented 1 year ago

GARSessionDelegate is a protocol, not a class, so I think you need to make it a class and also extend from NSObject.