What is Swift.AnyClass?

I studied the UITableView class and found:

 open func register(_ cellClass: Swift.AnyClass?, forCellReuseIdentifier identifier: String) 

Read here. I know that AnyClass is the current typical type.

 typealias AnyClass = AnyObject.Type 

I do not understand what it is: Swift.AnyClass What does Swift do?

I already know that this parameter is set to CustomTableViewCell.self

+2
syntax ios swift
Jan 17 '17 at 22:19
source share
1 answer

Just to clarify this, as someone has already said, Swift is the name of the virtual module for the runtime, each object, type and language embedded in it will also be available from this namespace.

In this case, why is the type declared as Swift.AnyClass instead of a simple AnyClass ?

I do not think this time it was necessary to avoid a collision of names with a specific type defined in the UITableView scope. This may be due to the fact that UIKit is still written in Objective-C.

They probably used a β€œworkaround” to use the more beautiful AnyClass type in the prototype of this function, which, as defined by the Swift runtime, would not normally be available in Objective-C as a global typedef.

I assume that they manually imported the Swift module (or a smaller layout module with several definitions) into UIKit, and what you see is the result of this.

+1
Jan 18 '17 at 10:41
source share



All Articles