When I pressed Command and clicked AnyObject to navigate to the interface of the AnyObject, I came across the below definition:
public typealias AnyObject
I see this comment written above the definition:
The protocol to which all classes implicitly conform.
Well I don't understand how this definition makes AnyObject a protocol without explicitly using the keyword protocol.
Also, it's a typealias without = someType, which is an invalid statement.
I can't write a statement like:
public typealias SomeOtherObject
It gives a compilation error.
Can anyone explain what exactly is happening here?
The thing is that by pressing on AnyObject holding CMD you will not actually see source code, but just a public interface. If you will go deep into Swift source code you will actually find out that
public typealias AnyObject
is actually looks like this:
public typealias AnyObject = Builtin.AnyObject
Here is the link to file containing this code https://github.com/apple/swift/blob/master/stdlib/public/core/Policy.swift