Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Matching Optional

假设服务器返回以上的JSON,客户端需要根据文章类型来作不同的布局。

enum Occupation: String {
  case AppSo = "app"
  case Number = "number"
}

let typeString = "mindStore"

switch Occupation(rawValue: typeString) {

  case .AppSo?:
    print("AppSo Article")

  case .Number?:
    print("Number Article")

  case nil:
    print("Article?")
}

抽取于:Matching with Swift's Optional Pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.