[swift-evolution] [Pitch] Reducing the bridging magic in dynamic casts

Charles Srstka cocoadev at charlessoft.com
Mon May 2 18:47:47 CDT 2016

> On May 2, 2016, at 5:53 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> I can't think of any problems that would block us from doing that today. It'd be pretty easy to write an ErrorProtocol extension that just forwards NSError's interface via bridging, and I bet that'd cover most use cases for 'as NSError':
> extension ErrorProtocol {
>  var domain: String { return NSError(self).domain }
>  var code: Int { return NSError(self).code }
>  var userInfo: [String: AnyObject] { return NSError(self).userInfo }
>  /* etc. */
> }
> -Joe

This could be fantastic if it accompanied the addition to ErrorProtocol of an “userInfo” property (or even _userInfo, although I’d really prefer that all three of these be de-underscored) that NSError(self) would pick up on when doing the conversion. Otherwise, we’re just going to have to keep on using custom .toNSError() methods instead of the official way, so it won’t matter if the latter is “as NSError” or “NSError(foo)” or something else.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160502/ab78c9ee/attachment.html>

More information about the swift-evolution mailing list