A diary about my first Pull Request Contribution to Swift Programming Language

Pitiphong Phongpattranont
Pitiphong’s blog
Published in
3 min readSep 8, 2018

--

A few months ago I found a weird behavior when I tried to click the deprecated Objective-C method fix-it in Xcode. The gist of this bug is that Xcode will use the Swift method name in the generated Objective-C header of Swift code.

I thought that was a bug in Xcode at first so I filed a radar. Then I realized that that may be a bug/behavior in the Swift compiler so I submited a bug to Swift bug tracker. After a few moment, Jordan Rose from Apple Swift team commented about an idea on how to fix it.

That’s how I started working on my first contribution on Swift Programming Language project. And this is a diary entry on how I did that contribution.

Preparing

I started working on this bug by pulling the latest Swift Programming Language codebase and built it. This may take a few hours depending on your machine and build configuration. I used Xcode as an IDE but built the code with the provided build script. You can see how to build/develop Swift Programming Language at Swift GitHub page. Swift Programming Language is written in C++, luckily I have some experience of C++ from working on the MailCore 2 open source project

Fixing the bug

Even though Jordan said that he would not say that this bug is a Starter Bug but I think I may be able to fix it. So I asked him for an advice and he gave me some advices on how to fix it

The first thing I did was finding the related code in the project. I used the Find In Project command in Xcode with the deprecated keyword. The result was pretty small which made my work easier than I thought.

Now, here’s come the real work part, I read the code, tried to understand it, thought about how to fix it and then wrote the code and test. During the development, I need to do some debugging but the problem is I can’t find a way to attach the lldb with the PrintAsObjC code (there might be a way but I just didn’t find it). What I did was that I print some log to the standard error and read the log instead of normal debugging process.

But the real main problem was the build time. I built the change with the normal build script which normally took about 10–15 minutes per build. I just found out later after I finished that you can do an incremental build with Ninja. That was my fault not to find a way and carefully read the documentation that earlier.

Submitting a PR

After I finished the first draft of the implementation, I decided to open a Pull Request so that I can gather a feedback before finishing the task (fix early) . I opened a PR and asked Jordan to review it.

Updating the PR

Jordan helped me a lot during this phase by reviewing the PR and gaving me some feedbacks including the code convention, test cases and some advices on how to improve the code. I updated my PR based on the Jordan’s feedbacks. There were several round trips and it took some time to do it since I live in Thailand where it is 14 hours difference from the California. Which means that I can make and answer the comment in PR once a day.

Celebration

After several round trips of feedback and fixes, finally my PR was merged into the Swift Programming Language 🎉

The change may not be included in Swift 4.2. I believed we can see it in the later version of Swift

Future Improvement

While I was waiting for a feedback, I thought of some improvement to the change I made. However Jordan suggested that it could be implemented in another PR and had the opened PR to be merged instead.

Acknowledgement

I want to thank Jordan Rose from the Swift team who helped me a lot since the beginning. I would not be able to make it without his advices and his helps

Now, it’s time for you to try to contribute

--

--

A long time iOS Developer who also interested on the Programming, User Interface and User Experience design. Want to see my code? https://github.com/pitiphong-p