什么是 Swift.AnyClass? [英] What is Swift.AnyClass?

查看:26
本文介绍了什么是 Swift.AnyClass?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 UITableView 类,我发现:

I was looking into UITableView class and I found:

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

阅读 这里 我知道 AnyClass 实际上是一个类型别名.

Reading here I know AnyClass is actualy a typealias.

typealias AnyClass = AnyObject.Type

我不明白的是:Swift.AnyClass Swift 是做什么的?

What I don't understand is what is: Swift.AnyClass What does the Swift do?

我已经知道它需要的参数类似于 CustomTableViewCell.self

推荐答案

只是为了澄清这一点,正如有人已经说过的,Swift 是运行时的虚拟模块的名称,每个对象,语言中定义的 type 和 builtin 也可以从此命名空间访问.

Just to clear this out, as someone already said, Swift is the name of the virtual module for the runtime, every object, type and builtin defined in the language will also be accessible from this namespace.

在这种情况下,为什么将类型声明为 Swift.AnyClass 而不是简单的 AnyClass?

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

我认为这次不需要避免与 UITableView 范围中定义的某些类型发生名称冲突.这可能与 UIKit 仍然用 Objective-C 编写的事实有关.

I don't think that it was required to avoid name-clashing with some type defined in UITableView scope this time. This could be related to the fact that UIKit is still written in Objective-C.

他们可能实施了一种解决方法",以在该函数原型中使用更好看的 AnyClass 类型,而在 Swift 运行时中定义的类型通常不会在 Objective-C 中作为全局 typedef 使用.

They likely implemented a "workaround" to use the better-looking AnyClass type in that function prototype, that being defined in the Swift runtime would not normally be available in Objective-C as a global typedef.

我的猜测是他们在 UIKit 中手动导入了 Swift 模块(或者一个只有几个定义的较小的模型模块),你看到的就是这样的结果.

My guess is that they manually imported the Swift module (or a smaller mockup module with just a few definitions) in UIKit and what you see there is the result of that.

这篇关于什么是 Swift.AnyClass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆