Search code examples
swiftreuseidentifierclass-attributes

How to declare class attributes in swift, just like UITableViewCell reuse identifiers?


I am trying to declare a reuse identifier associated to a UITableView subclass in swift.

From my understanding I would like to declare an class stored property (not an instance one) so i have access via: MyCustomTableCell.ReuseIdentifer.

Here is what I was trying:

class MyCustomTableViewCell : UITableViewCell {

    class let ReuseIdentifier = "MyCustomTableViewCellReuseIdentifier"

}

The compiler mentions that class attributes are not supported yet. How to declare such kind of constants associated to a class type in a clean way?


Solution

  • It's just as the compiler said, constants / variables cannot be declared at the class-level yet. The "yet" in the error is key: Apple does intend to add support for this feature, and if you wait a few Xcode releases, it should be available.