Skip to content

Instantly share code, notes, and snippets.

@Limon-O-O
Last active December 17, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Limon-O-O/0bba759c8e8e6dbfa39f to your computer and use it in GitHub Desktop.
Save Limon-O-O/0bba759c8e8e6dbfa39f to your computer and use it in GitHub Desktop.
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