Data: a swift-foundation deep-dive
Data is both ubiquitous and mysterious. It’s a block of binary. A bunch of bytes. Big deal? Data is the WD-40 that lubricates the gears of our applications. The colourless mana that converts network packets to domain objects, files to visible UIImages, or a WebSocket stream into live-chat. Big deal. For legacy reasons, Data lives outside the Swift standard library, in Foundation. Foundation and swift-foundationThe Foundation library is ancient by technological standards, with roots all the way back to the NeXTSTEP operating system that underpins macOS today. It provides basic functionality for all apps, such as data management, text processing, date and time tools, and networking. In 2022, swift.org announced an open-source, pure-Swift re-write of Foundation in The Future of Foundation. This was motivated by a push towards multi-platform Swift, untethered from Darwin. Swift developers can leverage familiar Foundation functionality while writing systems for the cloud, embedded devices, Windows, and maybe even Android! The swift-foundation source code is already used in production on Apple platforms, as part of the ubiquitous Foundation umbrella framework. It lives alongside legacy, non-rewritten, C and Objective-C code. Today, we’re going to look under the hood of swift-foundation and understand exactly how Data is implemented. How Foundation is implementedFirst, let’s jump straight to Data. Right at the top, we see the secret sauce of a cross-platform rewrite:
Continue reading this post for free in the Substack app |