Apple engineers, back in June this year introduced Swift System, a new library to interface with low-level currency types and system calls, and today, the company made it open source and added Linux support. The overall output now looks like an all in one solution for low-level system interfaces in Swift supported platforms.
According to GitHub, the idea behind Swift System is to present a one-stop solution to low-level system interfaces for all supported Swift platforms.
Today, the majority of the operating systems that we use are written in some system interface in C and it has remained unchanged for decades. These APIs can be used directly from Swift but such weakly typed system interfaces imported from C are more prone to error and therefore were unmanageable.
Just for example, in a UNIX like operating systems like Linux or Apple’s iOS, these weakly typed decade-old functions have faced several cons. In short, these old codes failed to utilize the expressivity.
The Swift System module has introduced several language features in order to improve expressivity and reduces the chances of error. For example, with Swift System, ‘System’ defines the open system call as a static function with defaulted arguments in the ‘FileDescriptor’ namespace.
If someone takes the pain of comparing this Swift version to the original C version, then he or she will find significant differences. This Swift system uses raw representable structures and option sets the traditional language, which in turn helps in identifying mistakes at compile. Moreover, they are easier to convert to and from the weaker C types. In the Swift system, errors are thrown using the standard language mechanism and cannot be missed at all.
In the Swift system, FilePath is a managed, null-terminated bag of bytes that conforms to ExpressibleByStringLiteral. This is far safer to work with than a UnsafePointer<CChar>.
Note that System is not a cross-platform library but a multi-platform one that provides a separate set of APIs and behaviors on every supported platform that closely reflects the underlying OS interfaces. In simple words, here, a single import will pull in the native platform interfaces specified for the Operating System that you have chosen.