Swift should provide an expression syntax similar to the
| Originator: | kristopherdjohnson | ||
| Number: | rdar://17257897 | Date Originated: | 10-Jun-2014 05:28 PM |
| Status: | Duplicate/17150065 | Resolved: | Duplicate/17150065 |
| Product: | Developer Tools | Product Version: | Xcode 6 |
| Classification: | Feature (New) | Reproducible: | N/A |
Summary:
Swift's "switch" is a statement, not an expression. That means that if one wants to use a switch to calculate a value, one has to wrap it in a function:
func stringFromInt(n: Int) -> String {
switch n {
case 1: return "1"
case 2: return "2"
default: return "Only 1 and 2 are numbers"
}
}
let myNumericString = stringFromInt(n)
It would be nice if this common pattern could be simplified by adding an expression to Swift that does the pattern matching of "switch" but which is treated as an expression. For example, if this new expression was called "match", it might look like this:
let myNumericString = match n -> String {
case 1: "1"
case 2: "2"
default: "Only 1 and 2 are numbers"
}
Steps to Reproduce:
N/A
Expected Results:
N/A
Actual Results:
N/A
Version:
Xcode 6
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Great minds think alike
http://openradar.appspot.com/radar?id=5824647949975552