# FileHandle in FoundationEssentials

**URL:** <https://forums.swift.org/t/filehandle-in-foundationessentials/83248>\
**Category:** Using Swift\
**Tags:** foundation\
**Created:** [November 16, 2025, 8:16pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248 "2025-11-16T20:16:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [November 16, 2025, 8:16pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/1 "2025-11-16T20:16:16Z")

</div>

According to the [announcement in the forums](https://forums.swift.org/t/what-s-next-for-foundation/61939), `FileHandle` should be part of FoundationEssentials. But currently it isn't. I know the new Foundation might still be a bit incomplete, but since a file handle seems to an essential (sic!) part of Foundation, I am wondering if it might have been replaced by something else, and if yes, is there a kind of list for replacements like that or for parts that are still missing? Do I have to import the full Foundation for now the get `FileHandle`?

---

<div class="post-metadata">

**Author:** ![lsb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lsb/32/27798_2.png) [@lsb](https://forums.swift.org/u/lsb)\
**Post date:** [April 16, 2026, 12:32pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/2 "2026-04-16T12:32:03Z")

</div>

I just hit this in Swift 6.3. Is there any lightweight replacement for `FileHandle` that I can use for now?

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [April 16, 2026, 1:00pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/3 "2026-04-16T13:00:34Z")

</div>

> [@lsb](#):
>
> Is there any lightweight replacement for `FileHandle` that I can use for now?

Would [`FileDescriptor`](https://swiftpackageindex.com/apple/swift-system/main/documentation/systempackage/filedescriptor) work in your case?

---

<div class="post-metadata">

**Author:** ![lsb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lsb/32/27798_2.png) [@lsb](https://forums.swift.org/u/lsb)\
**Post date:** [April 16, 2026, 1:28pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/4 "2026-04-16T13:28:19Z")

</div>

Looks like it should work. However, my code also supports macOS, so should I use `SystemPackage` for both macOS and Linux, or use `System` on macOS and `SystemPackage` on Linux?

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [April 16, 2026, 3:07pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/5 "2026-04-16T15:07:25Z")

</div>

IMO as of right now using [`swift-system` SwiftPM package](https://github.com/apple/swift-system/) consistently on all platforms is the easiest approach and gives you best compatibility with the rest of the ecosystem of existing packages that do the same. This may change in the future if this pitch proceeds further somehow "[Pitch: System in the toolchain](https://forums.swift.org/t/pitch-system-in-the-toolchain/84247)".

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [April 16, 2026, 3:35pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/6 "2026-04-16T15:35:55Z")

</div>

> [@Max\_Desiatov](#):
>
> IMO as of right now using [`swift-system` SwiftPM package](https://github.com/apple/swift-system/) consistently on all platforms is the easiest approach and gives you best compatibility with the rest of the ecosystem of existing packages that do the same.

We used to do this, but this approach is problematic if you later on need to interact with other packages that also use `System(Package)` but use conditional imports to pick one or the other on Apple vs. non-Apple platforms. `swift-subprocess` was the one that made us have to switch over to conditional imports.

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [April 16, 2026, 3:43pm UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/7 "2026-04-16T15:43:12Z")

</div>

We want to get out of the current mess with the multiple imports long-term but there’s still some philosophical issues to sort through. FilePath moving to the stdlib would greatly alleviate these and help swift-system clarify its role (and whether or where it belongs in the stack).

One question is whether we are providing a POSIX-esque world view for files or a very platform-specific approach. POSIX style int32 descriptors and Windows style DWORD\* handles are a quite bit different from each other the further into the weeds you get.

What are your needs from this type?

---

<div class="post-metadata">

**Author:** ![lsb](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lsb/32/27798_2.png) [@lsb](https://forums.swift.org/u/lsb)\
**Post date:** [April 17, 2026, 8:28am UTC](https://forums.swift.org/t/filehandle-in-foundationessentials/83248/8 "2026-04-17T08:28:14Z")

</div>

And yes indeed I just happen to be using `swift-subprocess` at the same time, so yesterday I did resort to `#if` dance.

Now the imports are even more chaotic just because we want to drop full Foundation:

```swift
#if canImport(FoundationEssentials)
  import FoundationEssentials
#else
  import Foundation
#endif
#if canImport(System)
  import System
#else
  import SystemPackage
#endif

```

Really hope we can avoid this madness in a near future...
