# Foundation without ObjC Interop?

**URL:** <https://forums.swift.org/t/foundation-without-objc-interop/24443>\
**Category:** Compiler\
**Created:** [May 12, 2019, 12:59pm UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443 "2019-05-12T12:59:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davez/32/478_2.png) [@DaveZ](https://forums.swift.org/u/DaveZ)\
**Post date:** [May 12, 2019, 12:59pm UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/1 "2019-05-12T12:59:53Z")

</div>

What does importing Foundation without ObjC interoperability enabled mean? How is this scenario expected to work? I ask because `stmt/errors_nonobjc.swift` superficially "tests" this scenario.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [May 12, 2019, 5:49pm UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/2 "2019-05-12T17:49:50Z")

</div>

I assume you are talking about the `!DEPLOYMENT_RUNTIME_OBJC` builds for Darwin.

Importing `Foundation` without Objective-C interoperability means that you are using swift-corelibs-foundation for the Foundation implementation on Darwin rather than the traditional Objective-C based `Foundation` implementation. This allows us to test the implementation of the Swift implementation of Foundation on Darwin.

CC: @millenomi

---

<div class="post-metadata">

**Author:** ![DaveZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davez/32/478_2.png) [@DaveZ](https://forums.swift.org/u/DaveZ)\
**Post date:** [May 12, 2019, 6:30pm UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/3 "2019-05-12T18:30:05Z")

</div>

So the test which prompted the question just mocks up a stub “Foundation” with pure Swift code. Does `swift-corelibs-foundation` depend on “bridging” like Foundation does?

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [May 13, 2019, 4:59am UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/4 "2019-05-13T04:59:58Z")

</div>

There is a concept of bridging in [Swift] Foundation. NSSwiftRuntime sets up some of that bridging some of the Foundation types to the CoreFoundation types. As an example, `CFString` is bridged to `NSString` which is bridged to `String`.

---

<div class="post-metadata">

**Author:** ![rauhul](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rauhul/32/35207_2.png) [@rauhul](https://forums.swift.org/u/rauhul)\
**Post date:** [May 13, 2019, 6:42am UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/5 "2019-05-13T06:42:52Z")

</div>

> [@compnerd](#):
>
> !DEPLOYMENT\_RUNTIME\_OBJC

How would one specify this option (or lack there of) when building a SPM package?

I only see a flag to define an option.

```swift
-D <value> Marks a conditional compilation flag as true

```

---

<div class="post-metadata">

**Author:** ![DaveZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davez/32/478_2.png) [@DaveZ](https://forums.swift.org/u/DaveZ)\
**Post date:** [May 13, 2019, 1:37pm UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/6 "2019-05-13T13:37:23Z")

</div>

So what motivated this discussion is that I experimented with having `ASTContext::getBridgedToObjC` always return `Type()` if ObjC interoperability is disabled. This broke one test: `stmt/errors_nonobjc.swift`

If `swift-corelibs-foundation` requires bridging but not the ObjC runtime, then `getBridgedToObjC` probably ought to be renamed, right?

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [May 13, 2019, 2:47pm UTC](https://forums.swift.org/t/foundation-without-objc-interop/24443/7 "2019-05-13T14:47:48Z")

</div>

Ah, yes, that has grown disjoint from the original name and no longer fully represents what it is meant to be. Renaming would probably be a good idea so that someone else doesn't trip over the same mine.
