Swift pattern matching with enum and Optional tuple associated values

萝らか妹 提交于 2019-12-04 10:05:46

You can use the .Some(x) pattern (.some(x) in Swift 3):

case .GetStops(let .Some(stopCode)):
     return ("GetStops.json", ["stopCode" : stopCode])

As of Swift 2 (Xcode 7), this can be shorter written as x? pattern:

case .GetStops(let stopCode?):
     return ("GetStops.json", ["stopCode" : stopCode])

The associated value is tested to be non-nil and unwrapped (similar as in an optional binding).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!