Xcode-beta (7A121l): Allow Creating Regular Expressions in Swift Without a Possible Exception

Originator:john
Number:rdar://21675110 Date Originated:04-Jul-2015 04:59 PM
Status:Open Resolved:
Product:OS X SDK Product Version:Xcode-beta (7A121l)
Classification:Feature (New) Reproducible:Always
 
Summary:
There is currently only one way to create a regular expression in Swift, with an initializer that can throw an exception. This means that there is no way to create an exception and store it in a local variable without making the variable optional or putting all the relevant work in a do/catch block. This is particularly frustrating when creating a regular expression from a string literal. The developer may have static knowledge that the regular expression, but there is no way to convince the compiler of this, and the developer has to work around this absence of compiler-time information.

This could be addressed through a first-class language construct for regular expressions. Another option would be a mechanism for creating a special regular expression to serve as a fallback for type-safety, which the developer knows cannot be invoked due to the static knowledge about the validity of the literal expression.

Steps to Reproduce:

Expected Results:

Actual Results:

Regression:

Notes:

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!