Apple’s Future Foundation: A Swift, Open Source Evolution

Ihor Malovanyi
5 min readApr 27, 2023

Apple recently unveiled the future of its Foundation framework, a staple in nearly all Swift projects. Foundation provides essential functionality (strings, collections, and dates) and sets conventions for excellent Swift code. The framework is transforming significantly, introducing an open-source, Swift-native implementation. This article will explore these changes and what they mean for the Swift development community.

Before starting reading, make sure you are not russian. By continuing reading, you confirm that you condemn the war in Ukraine unleashed by russia.

Glory to Ukraine! 🇺🇦

Introduction

As the new Foundation framework evolves, it brings additional opportunities for developers, the Swift ecosystem, and the broader community. This article will discuss how the new Foundation will impact app development, tooling, and collaboration.

The New Open-Source Foundation

In 2016, Apple started the swift-corelibs-foundation project, which provided an open-source Swift version of Foundation built on a preexisting, open-source C implementation. As Swift has grown, the need for a more efficient, open-source Foundation has emerged. Apple has announced an all-new open-source Foundation project written in Swift for Swift. This change brings numerous technical and community advantages:

  1. No more wrapped C code: The native Swift implementation eliminates conversion costs between C and Swift, resulting in faster performance. It also makes it easier for Swift developers to understand and contribute code.
  2. Smaller, more granular packages: The rewritten Foundation offers a range of packages that suit different needs, such as FoundationEssentials, FoundationInternationalization, FoundationObjCCompatibility, and more.
  3. Unify Foundation implementations: A single, canonical implementation of Foundation will reduce divergent behavior and bugs across platforms.
  4. Open contribution process: Developers can contribute new API to Foundation, fostering community-driven growth and improvements.

Foundation Package Preview

On April 26, 2023, Apple released a preview of the future Foundation on GitHub. The preview includes a unified implementation of Foundation, which is faster, safer, and more accessible to new contributors. A Foundation Workgroup will oversee proposed Foundation API reviews and coordinate with the Swift community and Apple engineering.

Current State

The preview package includes several types, such as JSONEncoder, Calendar, TimeZone, and Locale, among others. Many types are brand-new Swift implementations, while FormatStyle and ParseStyle are open-source for the first time. The FoundationICU package provides internationalization support on non-Darwin platforms.

Performance Improvements

The new Swift implementation offers significant performance benefits over the previous C and Objective-C versions. Locale, TimeZone, and Calendar no longer require bridging from Objective-C, resulting in substantial speed increases. Date formatting using FormatStyle is also much faster, with a 150% improvement in some benchmarks.

The new package features a Swift implementation for JSONDecoder and JSONEncoder, eliminating costly roundtrips to and from the Objective-C collection types. Additionally, JSON decoding has seen significant improvements. Benchmarks show decode time improvements ranging from 200% to 500%.

App Development

  1. Improved performance: The new Foundation, with its Swift-native implementation, significantly reduces overhead in many common tasks. The faster performance will allow developers to create more responsive and efficient applications.
  2. Modular design: The new Foundation offers various packages to suit different needs. Developers can choose specific packages for their projects, which helps reduce binary sizes and dependencies. This modular design leads to more streamlined, maintainable codebases.
  3. Seamless integration with Swift features: The new Foundation aims to take full advantage of Swift language features, such as value semantics and Codable types. This integration will enable developers to write more expressive, safe, and efficient code.
  4. Cross-platform consistency: The unified Foundation implementation will reduce discrepancies and potential bugs when moving code between platforms. This consistency will make it easier to develop cross-platform applications and libraries.

Tooling

  1. Compatibility with the Swift Package Manager: The new Foundation will be distributed as a package, making it easier for developers to integrate into their projects using the Swift Package Manager.
  2. Improved debugging and profiling: As a Swift-native framework, the new Foundation will provide better debugging and profiling support within Swift tooling, such as LLDB and Instruments.
  3. Continuous evolution with the Swift language: The new Foundation will closely align with Swift’s ongoing development, ensuring that it takes advantage of new language features and optimizations.

Collaboration

  1. Community-driven development: The open contribution process allows developers from around the world to contribute new APIs, bug fixes, and optimizations. This collaborative approach will help drive the framework’s growth and ensure it meets the needs of a diverse range of developers and use cases.
  2. Foundation Workgroup: The workgroup will oversee API proposals, coordinate with the Swift project, and guide the library’s evolution. This governance structure will help maintain a consistent vision for Foundation while ensuring it remains responsive to community input.
  3. Shared knowledge and resources: The open-source nature of the new Foundation enables developers to learn from its code, contribute to its development, and share their experiences with the broader community. This shared knowledge will help improve Foundation and the wider Swift ecosystem.

Next Steps

The Foundation project’s primary goals are quality and performance. In the first half of 2023, the focus will be on refining core API, expanding unit and performance tests, and porting to other platforms using relevant code from swift-corelibs-foundation. The project also aims to accept a small number of community proposals for new APIs in 2023, with more contributions expected in the future.

Conclusion

The new Foundation framework promises exciting advancements for Swift developers, the ecosystem, and the broader community. By offering performance gains, modular design, seamless integration with Swift features, and an open contribution process, Apple is setting the stage for a more collaborative and dynamic future in Swift app development. As developers embrace these new opportunities, we can expect to see even more innovative and high-quality applications, tools, and libraries in the Swift ecosystem.

Links

One more thing…

If you like my content and want to support me, please buy me a coffee and subscribe!

Also, I have the Telegram channel Swift in UA, where you can find more exciting things.

Thank you for reading. See you soon!

--

--