# What is the ObjC counterpart for \_ObjectiveCBridgeable?

**URL:** <https://forums.swift.org/t/what-is-the-objc-counterpart-for-objectivecbridgeable/39580>\
**Category:** Using Swift\
**Tags:** bridging, objc\
**Created:** [August 21, 2020, 2:52pm UTC](https://forums.swift.org/t/what-is-the-objc-counterpart-for-objectivecbridgeable/39580 "2020-08-21T14:52:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nickolas\_Pohilets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nickolas_pohilets/32/10659_2.png) [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Post date:** [August 21, 2020, 2:52pm UTC](https://forums.swift.org/t/what-is-the-objc-counterpart-for-objectivecbridgeable/39580/1 "2020-08-21T14:52:54Z")

</div>

I'm trying to implement a transparent ObjC\<-\>Swift bridging for my custom type.

I've conformed Swift type to `_ObjectiveCBridgeable`, and when imported into ObjC, all usages of it are automatically bridged. But when bridging ObjC usages into Swift, they are still seen as ObjC classes, even though compiler sees conformance to `_ObjectiveCBridgeable` and offers to insert `as`.

I could mark ObjC usages as `NS_REFINED_FOR_SWIFT` and provide necessary wrappers in Swift extensions, but that's a lot of boilerplate code.

Is there something I could use on ObjC side to make ObjC usages bridged to Swift type automatically?

Example code:

```nohighlight
NS_REFINED_FOR_SWIFT
@interface Foo : NSObject
@end

@interface Bar: NSObject
@property(nonatomic, copy) Foo *single;
@property(nonatomic, copy) NSArray<Foo *> *array;
@end

void test() {
    Baz* baz = [Baz new];
    Foo *single = baz.single; // OK
    NSArray<Foo *> *array = baz.array; // OK
}

```

```swift
public struct Foo: _ObjectiveCBridgeable {
    public typealias _ObjectiveCType = __Foo
    public func _bridgeToObjectiveC() -> __Foo {__ Foo() }
    ...
}

@objc public class Baz: NSObject {
    @objc public var single: Foo = Foo()
    @objc public var array: [Foo] = []
}

func test() {
    let bar = Bar()
    let single: Foo = bar.single // ERROR: '__Foo' is not implicitly convertible to 'Foo'; did you mean to use 'as' to explicitly convert?
    let array: [Foo] = bar.array // ERROR: cannot assign value of type '[__Foo]' to type '[Foo]'
}

```

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 21, 2020, 4:27pm UTC](https://forums.swift.org/t/what-is-the-objc-counterpart-for-objectivecbridgeable/39580/2 "2020-08-21T16:27:14Z")

</div>

\_ObjectiveCBridgeable cannot be used outside of the standard library.
