apple/swift-corelibs-foundation logo

apple/swift-corelibs-foundation

Free

The Foundation Project, providing core utilities, internationalization, and OS independence

FreeFree tier
Type
Open Source

About apple/swift-corelibs-foundation

The Foundation framework defines a base layer of functionality required for almost all applications. It provides primitive classes and introduces several paradigms for functionality not provided by the Objective-C runtime or Swift standard library. This project, swift-corelibs-foundation, is a compatibility implementation of the Foundation API for platforms without an Objective-C runtime, such as Linux and Windows. It is designed to support a small set of basic utility classes, consistent conventions, internationalization and localization, and OS independence. The project provides core types including URL, Data, JSONDecoder, Locale, Calendar, NSObject, NSFormatter, and NSKeyedArchiver, and re-exports FoundationEssentials and FoundationInternationalization modules for source compatibility.

Key Features

Cross-platform compatibility implementation of Foundation API for non-Darwin platforms (Linux, Windows)
Provides core utility classes: URL, Data, JSONDecoder, Locale, Calendar, NSObject, NSFormatter, NSKeyedArchiver
Supports internationalization and localization via ICU integration
Re-exports FoundationEssentials and FoundationInternationalization modules for pre-Swift API compatibility
Open source, maintained under the Swift project by Apple
Builds FoundationNetworking and FoundationXML modules

Pros & Cons

Pros
  • Provides essential Foundation API for Swift outside Apple platforms, enabling code portability
  • Backed by Apple's Swift project with active community and contributions
  • Includes internationalization support via ICU, consistent with Darwin platforms
  • Best-effort compatibility allows reuse of existing Swift code that depends on Foundation
Cons
  • Compatibility is best-effort and may differ from the Objective-C Foundation implementation on Apple platforms
  • Not intended for use on macOS/iOS (should use system Foundation instead)
  • Some advanced Foundation features (e.g., NSKeyedArchiver) may have limitations or behavior differences
  • Updates and new features may trail behind the Darwin Foundation releases

Best For

Developing Swift applications on Linux or Windows that require Foundation APIPorting macOS/iOS applications to server-side or cross-platform environmentsBuilding command-line tools or server-side Swift services needing data handling, JSON parsing, or localizationLearning Foundation internals or contributing to the Swift open-source ecosystem

FAQ

What is swift-corelibs-foundation?
It is the open-source compatibility implementation of the Foundation framework for Swift, designed for platforms that lack an Objective-C runtime, such as Linux and Windows.
How does it relate to swift-foundation?
swift-corelibs-foundation provides a compatibility layer for pre-Swift Foundation API and re-exports modules from the newer swift-foundation project (FoundationEssentials, FoundationInternationalization) for source compatibility.
Can I use this on macOS or iOS?
No, on Apple platforms you should use the built-in Foundation framework that comes with the operating system. This project is for non-Darwin platforms only.