[关闭]
@zhangyuhangk 2015-07-22T07:06:25.000000Z 字数 311 阅读 1055

Swift2中enum的一个new feature

swift


Swift2的enum新增了一个功能: String类型的enum如不指定rawValue,其值等于字面上的值(……表达能力捉急……)。看具体的例子吧:

  1. enum Direction: String {
  2. case East = "East"
  3. case South = "South"
  4. case West = "West"
  5. case North = "North"
  6. }

现在可以写成:

  1. enum Direction: String {
  2. case East, South, West, North
  3. }

是不是简洁了许多?

知道这个feature后,我迫不及待地把工程里所有的cell identifier定义成enum(这也是官方推荐作法)

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注