[Review] SE-0058: Allow Swift types to provide custom Objective-C representations

Generally I'm +1 on this, but I do have a concern. It's not made explicit

in the proposal, but I presume that this is meant to only be available on
Darwin, and not Linux or other platforms that don't have swift using the
Objective-C runtime? (Please correct me if I am mistaken.)

I ask because of the swift-corelibs-foundation project; Presumably once

that is complete for Swift 3, code that makes use of this type bridging
should be able to be run cross-platform. For example:

var a = [AnyObject]()
(a as NSArray).addObject(NSObject()) // should this work on all


swift-corelibs-foundation uses its own protocol named

_ObjectTypeBridgeable (defined here:


) to simulate what happens today on Darwin platforms, but there is no

language support for it so API consumers must explicitly call its bridging
methods. It would be great if corelibs-foundation (and any code designed to
work on Linux) could take advantage of this proposal to provide the
language support, and if the proposal as written is not intended to have an
effect on Linux at all, then I would suggest we modify it so that the
resulting implementation is not tied to Objective-C and Darwin only.


This is a very timely observation. Following a suggestion from Tony
Parker, I've prototyped using (abusing?) ObjectiveCBridgeable to enable
this kind of conversion for swift-corelibs-foundation on Linux (where there
is no Objective-C runtime). The motivation is to get consistent
cross-platform bridging.

On the plus side, the change is pretty straightforward and seems to be
working as expected (still working through all the TestFoundation test
cases and replacing bridge() calls with as operations). I expect to
complete the initial pass through the foundation test cases by the weekend.

On the minus side, the name becomes a little misleading. We are really
using ObjectCBridgeable to bridge from one Swift type to another Swift

For the curious, the relevant pull requests are:
  Basic usage of ObjectiveCBridgeable protocol on Linux by dgrove-oss · Pull Request #303 · apple/swift-corelibs-foundation · GitHub

Would be interested in comments on the approach.




On Apr 5, 2016, at 5:57 PM, Kevin Lundberg via swift-evolution < swift-evolution at swift.org> wrote: