Skip to content

Instantly share code, notes, and snippets.

@rslifka
Created October 23, 2021 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rslifka/6f923fe332ed4f8706d1e449cee4fd93 to your computer and use it in GitHub Desktop.
Save rslifka/6f923fe332ed4f8706d1e449cee4fd93 to your computer and use it in GitHub Desktop.
Cannot declare conformance to 'NSObjectProtocol' in Swift
import AuthenticationServices
class Awesome: ASWebAuthenticationPresentationContextProviding {
// ERROR: Cannot declare conformance to 'NSObjectProtocol' in Swift
...
}
import Foundation
import AuthenticationServices
class Awesome: NSObject, ASWebAuthenticationPresentationContextProviding {
...
}
@rslifka
Copy link
Author

rslifka commented Oct 23, 2021

Initially found here while searching for the error message.

Presumably this is because ASWebAuthenticationPresentationContextProviding (Apple Swift Docs) inherits from NSObject? I'm not familiar with Objective-C, perhaps everything inherits from NSObject the way everything inherits from java.lang.Object in Java?

My understanding is that by extending NSObject we implement everything the NSObject-extended protocol requires, thus allowing us to satisfy the requirements for ASWebAuthenticationPresentationContextProviding implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment