Thanks, If the following (from @codafi's stack overflow answer) is true:
The difference lies in the semantics of @objc declarations. With AnyObject, the expectation is that conforming classes may or may not be proper Objective-C objects, but the language treats them as such anyway (in that you lose static dispatch sometimes).
Does this mean that inheriting from AnyObject might incur a performance overhead (compared to if class had been used)?
The StackOverflow answer is out of date as of Swift 4. protocol P : class {} and protocol P : AnyObject {} parse identically and there's no semantic difference between them. We should add a warning to deprecate the former at some point.
The StackOverflow answer is out of date as of Swift 4. protocol P : class {} and protocol P : AnyObject {} parse identically and there’s no semantic difference between them. We should add a warning to deprecate the former at some point.
But even @jrose prefers class in his WWDC 2018 talk
Don't worry, you weren't the only presenter with imperfect Swift code. I'm pretty sure I remember a session where the presenter typed out -> Void return types. It's fairly clear that many Apple's still aren't that familiar with Swift. For some, I'm guessing WWDC slides and presentations may be the only time they write Swift at all. At least I haven't noticed any semicolons this year!
Both keywords behave identically. AnyObject is preferred because it is the name of a type and can appear anywhere that a type can. "class" is just special syntax in that one place in a protocol's inheritance clause, and it parses identically to "AnyObject".
This proposal merges the concepts of class and AnyObject , which now have the same meaning: they represent an existential for classes. To get rid of the duplication, we suggest only keeping AnyObject around. To reduce source-breakage to a minimum, class could be redefined as typealias class = AnyObject and give a deprecation warning on class for the first version of Swift this proposal is implemented in. Later, class could be removed in a subsequent version of Swift.
You can use either one, but I suggest using AnyObject since it can be used in more places (such as protocol compositions, eg MyProto & AnyObject). Also I’d like us to add a warning that class is deprecated at some point (this would make for a great starter bug if anyone is interested).