[swift-evolution] [Proposal draft] NSError bridging
dgregor at apple.com
Thu Jun 30 12:44:38 CDT 2016
> On Jun 30, 2016, at 2:19 AM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> Note that, unlike with NSError, the provided errorUserInfo requires String keys.
> Is there any way this could be tightened further to require Error.UserInfoKey keys (where Error.UserInfoKey is a Notification.Name-style wrapper)?
Maybe. We had originally tried doing this, but it caused a lot of frustration because NSError’s userInfo historically allowed non-string keys, so technically it should be typed as [NSObject : AnyObject]. However, that type signature means that one is “.rawValue”’ing all of the keys over and over:
userInfo[NSErrorUserInfoKey.myKeyName.rawValue] = foo
That said, this proposal eliminates the need for using those keys (and, indeed, NSError) most of the time, and maybe we can write off non-string keys entirely in Swift.
More information about the swift-evolution