I wanted to play around with Swift and get a hang of it so I wrote a little demo app that I’ve been wanting to write for a while.
On OS X in the /usr/standalone/i386/EfiLoginUI folder there are some efires files that are apparently used in Apple’s EFI code that loads at startup. The files store mostly PNG images in a simple binary file format.
I put together a small Swift program that parses these files and lists the images within them.
One thing I wasn’t able to figure out is how to extract values from a C array. I found a workaround for using NSData by using Swift’s ability to pass a pointer to an array. Since this worked, I’m assuming that Swift pointers of basic types are like C arrays and C++ vectors, and they store their data contiguously.
The other tricky part was creating a string from an ASCII character value. The Character class didn’t seem to have any constructors, but I found UnicodeScalar which can take an int and can be used by Character and String constructors.
Overall, I like Swift and the simple things like not having a separate header file makes for cleaner code. If you know Objective-C you can pick this up easily. The optionals are probably the biggest thing to learn about Swift at this stage.
There are still areas for improvement so I’ll be looking forward to the final 1.0 release this fall but definitely plan on migrating some of my other projects to Swift.