[swift-evolution] [Review] SE-0116: Import Objective-C id as Swift Any type

Joe Groff jgroff at apple.com
Wed Jul 20 15:52:18 CDT 2016

> On Jul 8, 2016, at 11:19 AM, Ben Langmuir <blangmuir at apple.com> wrote:
> Hey Joe,

Sorry Ben, missed this when you sent it a couple weeks ago.

> I’m +1 on the overall direction, but I have some questions/concerns about the "Ambivalent dynamic casting from Any” section.
> 1) When you suggest that `x as String` succeeds but `x as NSString` fails, I assume this would only be true *after* SE-0083, since otherwise we’d be violating transitivity of `as` casts?

Right. I think we'll have to subset this part out of the proposal altogether and leave casting as is, though, due to time constraints.

> 2) Have you considered the only allowing `as` casts to the bridged type (e.g. String) for values coming from `id` at the language level, but providing some guaranteed optimization that if you immediately convert to the ObjC class type (ie. NSString(x as! String)) we give zero-cost round-tripping? Would that be detectable?  I think making `value as? NSFoo` fail or succeed depending on whether the value came from ObjC  will be a source of subtle bugs.  What if I have multiple sources of values - some from ObjC, some from Swift - and stuff them into an [Any].

Yeah, John's looking into that as a general peephole.


More information about the swift-evolution mailing list