Swift optional binding with tuples

后端 未结 4 1660
挽巷
挽巷 2021-01-04 04:44

I\'m trying to use a tuple as an optional binding in an IF statement in Swift but it won\'t compile and that error message is less than helpful. Why doesn\'t the following

4条回答
  •  时光取名叫无心
    2021-01-04 05:26

    In Swift 2 with optional pattern matching you can write

    if case let (user?, pass?) = (user, pass) { }
    

    This is especially useful if, for example, (user, pass) is a tuple stored in a variable.

提交回复
热议问题