swift - 如何在 swift 中声明类属性,就像 UITableViewCell 重用标识符一样?

标签 swift reuseidentifier class-attributes

我正在尝试在 swift 中声明与 UITableView 子类关联的重用标识符。

根据我的理解,我想声明一个类存储属性(不是一个实例),所以我可以通过以下方式访问:MyCustomTableCell.ReuseIdentifer。

这是我正在尝试的:

class MyCustomTableViewCell : UITableViewCell {

    class let ReuseIdentifier = "MyCustomTableViewCellReuseIdentifier"

}

编译器提到尚不支持类属性。如何以干净的方式声明与类类型关联的此类常量?

最佳答案

正如编译器所说,常量/变量还不能在类级别声明。错误中的“尚未”是关键:Apple 确实打算添加对此功能的支持,如果您等待几个 Xcode 版本,它应该可用。

关于swift - 如何在 swift 中声明类属性,就像 UITableViewCell 重用标识符一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24123319/

相关文章:

C# 类和 Oracle 映射参数

python - 未找到 load_resource 函数作为 FPDF 的类方法

ios - UIAlertAction 值列表

ios - dequeueReusableCellWithIdentifier :forIndexPath: VS dequeueReusableCellWithIdentifier:

iPhone - 什么是重用标识符(UITableViewCell)?

ios - 正确的子类化和重用 UITableViewHeaderFooterView

swift - AVPlayer 不播放音频

ios - 如何在 UIView 中制作透明孔

swift - "Copy swift standard libraries"构建步骤不包括 SwiftOnoneSupport.dylib