Why is the static keyword used in UITableViewCell identifiers?

前端 未结 3 1493
挽巷
挽巷 2021-02-01 05:31

I\'ve read up on \"static\" on several occasions, including just before posting this question. I\'m still searching for an \"Aha\" though.

In the context of UITableView\

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 05:49

    There's no real benefit here. It's mostly just a hint to the reader that the same value is used for all cells in this particular bit of code. As the identifier itself is a constant string, it gets compiled into an immutable chunk of memory and referenced as the same pointer every time, e.g. there is no cost involved in constructing the string even if you remove the static keyword.

提交回复
热议问题