My Swift Mentorship Journey

For over six years, I've been working as an iOS developer, and during this period I had the opportunity to work with both ObjC & Swift on various projects. My initial entry into the iOS world was facilitated by my prior experience with C, given its compatibility with Objective-C. So I had an affinity with low level programming before starting out my iOS journey.

Throughout these years, I often contemplated the idea of experimenting with C or C++. However, I perceived this endeavour to be quite demanding and challenging. I wasn't particularly familiar with the world of open source, and it had never occurred to me to consider it as a viable starting point for this journey.

Furthermore, I was somewhat reluctant to seek assistance or connect with individuals to obtain specific advice on where to begin. This reluctance stemmed from my perception of coding as less of a social activity and more of a skill-based endeavour.

Before discussing my goals, I believe it's important to explain why I chose libdispatch. Five months ago, I came across an article discussing how Grand Central Dispatch (GCD) could be used for executing tasks serially. In the example provided, there was a particular case that I couldn't fully comprehend. To address this, someone recommended that I explore the libdispatch repository. At that time, without any help, it seemed hopeless. But then, I discovered the mentorship program and I said this could be a great opportunity to have a deep dive into the internals of GCD.

Given my previous experience with GCD, my initial goal was to gain a better understanding of how it functions behind the scenes. I had read in various articles that, for macOS, GCD has a special implementation that interfaces directly with the kernel. However, considering the complexity of this project, I decided to start by getting my hands dirty with a simpler task. As I looked through the repository, I noticed the Swift testing task and contacted the top contributor to confirm its feasibility.

After a couple weeks of digging into the repository and getting familiar with Cmake & Ninja, I decided to focus on completing this task as my primary goal. I deferred my initial goal of understanding the inner workings of GCD for a later time. My main focus now is to write tests for the Swift interface of GCD.

The journey began with a meeting with my mentor, David. We discussed the possible repositories to contribute to. As I set my sights on libdispatch, I wanted to find out if the Swift testing task was still viable. After validating that possibility, I began working on the project. The first step was to build the project. Initially, I aimed to build it on macOS, but I later discovered through a conversation with Saleem that this was not possible because it relies on functions from the kernel that are not available on macOS. So, I proceeded to build it on Linux.

During the building phase, I realised that having a basic knowledge of CMake was essential to make faster progress. It felt like a roadblock for me, so I dedicated some of my time to learning CMake by creating a dummy project. I learned the basic structure of a CMakeLists file, some fundamental CMake commands, and how to link a library into another project at a deeper level, including the need to use an include directory path and how the linker searches for specific dependencies.

After completing this step, the next one was to discuss the test harness. Saleem warned me against using an external dependency, as the pull request would likely be rejected. XCTest was not an option either, because it had a dependency on libdispatch, making it impossible to build one without the other. Therefore, the only viable solution was to create a custom test harness. At this point, I experienced a lot of confusion. I wasn't aware that CTest serves as both a test helper baked directly into CMake and a test library. Once again, Saleem came to the rescue and explained the differences between the two. From that point on, it was clear which direction to take. Not long after, I managed to run a Swift test with the CTest binary helper. Additionally, my mentor David provided a great idea on how to avoid importing Foundation to access the exit call on which CTest relies to pass or fail a test.

The next step was to use the created libdispatch library in both a C and a Swift executable to ensure that everything worked smoothly and that I could use the newly created library. The C part was simple, but the Swift part presented challenges. With the assistance of Saleem, I am currently investigating why the linker is selecting the system GCD from the Swift toolchain instead of the custom one. In this case, it's valuable to gain a deeper understanding and experiment further with the Swift compiler and linker.

When I first embarked on this journey, I was a bit nervous, thinking that things would be much more challenging. Despite always being passionate about understanding how computers execute operations behind the scenes, I had never had the opportunity to work so closely with them. Moreover, I had the misconception that you needed a lot more knowledge to start with low-level programming. In retrospect, I was mistaken.

In addition to the valuable experiences and knowledge I gained during this journey, I also discovered another significant aspect of open source projects. The people who work on these projects are not only highly knowledgeable but also incredibly helpful and humble. They are always willing to assist and guide you in your endeavours. Their involvement and willingness to help are truly amazing. I want to extend a big shoutout to both @ronnqvist and @compnerd, who were exceptionally kind and helpful throughout this journey.

As for my future plans, I aim to complete my current testing task on libdispatch. Additionally, I'm interested in contributing to more complex tasks related to libdispatch, particularly its port to Windows. In the initial stages, I asked Saleem for resources to better understand the fundamental concepts necessary for working on such projects. Consequently, I'm interested in digging deeper into understanding how operating systems function.

On a personal note, I feel that I have successfully overcome an irrational belief that demanded I be 100 percent prepared before starting something new. I've come to realise that, in reality, the more you are passionate about something, the more time and effort you are willing to invest in it. I've learned to trust the process more, even when things seemed daunting. With time and effort, significant progress can be made.

In conclusion, I am genuinely grateful for the opportunities I have received. I want to take this moment to express my sincere thanks to all who have supported and guided me in this journey!