[swift-evolution] [Discussion]: Deprecate !-Unwrapping of Optionals
davesweeris at mac.com
davesweeris at mac.com
Mon Feb 29 14:59:22 CST 2016
> On Feb 29, 2016, at 2:24 PM, Developer via swift-evolution <swift-evolution at swift.org> wrote:
>
> And for those cases there will be a standard library function or something more obvious than bang to make up for the deprecated operator. Force unwrapping will not go away (that's a terribly unproductive idea), but the goal is to make a dangerous operation more obvious[ly dangerous].
Like this?
enum OptionalUnwrappingError : ErrorType {
case unexpectedlyFoundNil
}
enum Optional<T> {
typealias Wrapped = T
case None
case Some(Wrapped)
...
func unwrap() throws -> Wrapped {
switch self {
case .None: throw OptionalError.unexpectedlyFoundNil
case .Some(let value): return value
}
}
}
It’s hard to get more obvious than the compiler complaining that you haven’t wrapped a throwing function in a try block
- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160229/25fc1c0a/attachment.html>
More information about the swift-evolution
mailing list