> Am 12.04.2016 um 01:01 schrieb Yuta Koshizawa <[email protected]>: > > Hi. > > Decoding a JSON is just an example. As I replied to Thorsten, we can > think about various cases we want to unwrap multiple optionals at > once. > > This is another example (with the notation `|?` and the postfix > version I proposed instead of the infix `???`). > > ``` > do { > let sum = try Int(aString)|? + Int(bString)|? > } catch _ { > // Error handling > } > ``` > > With optional binding, we need to write something like the following. > It needs additional assignments (bindings) to `a` and `b`. > > ``` > if let a = Int(aString), b = Int(bString) { > let sum = a + b > } else { > // Error handling > } > ```
Actually I find this much more readable than the version above which mixes error handling (|?) and the business logic (a + b), making the business logic more difficult to understand. Using meaningful names instead of `a` and `b` will increase readability even more. -Thorsten _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
