Swift: Enum#init?(rawValue:) should throw instead of returning an optional value
| Originator: | dennis | ||
| Number: | rdar://22870831 | Date Originated: | 26-Sep-2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Enhancement | Reproducible: | N/A |
In Swift, `nil` marks successfully finding no value while `throws` means being unable to find a value because of a precondition or runtime failure. Your own compiler error messages (try making a function that throws and also returns an optional, and mark it @objc -- "Throwing method cannot be marked @objc because it returns an optional value of type T?; 'nil' indicates failure to Objective-C"). This, however, is not followed by the Enum#init?(rawValue:) initializer, which returns nil if it fails to find a matching case for the given raw value, meaning `nil` indicates failure`, which directly goes against the Swift way of thinking.
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!