Any :Any is an alias for an empty protocol collection that indicates that no protocol is implemented, so it can be any type, including class instances and struct-body instances. Any is an alias.
///A protocol type that is respected by any type
Typealias any = protocol<>
Anyobject:
Anyobject is a member of an empty protocol, and any object implements this protocol.
Check it out. Anyobject definition of:
@objc protocol Anyobject {
}
Anyclass:
Anyclass is the nickname of Anyobject.type.
See a under definition of Anyclass:
Typealias Anyclass = Anyobject.type
@objc is a declarative attribute used to decorate any declaration that can be accessed or used in OBJC , such as non-nested classes, protocols, properties and methods in classes and protocols, initializers, destructors, and subscripts. If you apply the OBJC attribute to a class or protocol, it is also implicitly applied to the members of that class or protocol. For classes marked with the OBJC attribute, the compiler implicitly adds the OBJC attribute to its subclasses.
Anyobject is decorated with @objc declaration attributes because it is meant to be a messenger of OBJC and Swift , and there are many types of transitive variables anyobjct .
Unlike any ,anyobject is an empty protocol that does not declare any members, and is any that represents an empty set of protocols.
Summarize:
Anyobject is a protocol, any is 0 protocols! anyobject is used for any class instance , and any is for any variable.
Check it out. definition of Anyobject:
@objc protocol Anyobject {
}
See a under definition of Anyclass:
Typealias Anyclass = Anyobject.type
Anyclass-it's really just an alias. Any is also an alias and an alias for protocol<> .
What is the difference between Swift's entry into the pit--any, Anyobject and Anyclass