iOS | Doing Code Reviews using Xcode

How to provide better Code Review feedback using Xcode

HAO-TI, FAN
Tech@Travelstart
4 min readJun 18, 2017

--

View the original article in Mandarin here.

(Photo by Émile Perron on Unsplash)

Sometimes, after we finish a feature, we will push a feature branch to the GitHub, then create a PR (Pull Request) for team to do code review.

We will switch to “Files changed ➝ Split mode” to review every files, and every parts where be changed in this PR.

And recently, I’ve learned a great way that also can help us to do code review.

That is “Directly doing Code Review using Xcode”.

Let’s see how we work step by step.

First, if there is someone who has already finished a feature, then pushed its feature branch to the gitHub, and created a PR.

: feature/mainpage-implementation

You can see the newest tree in your git GUI (I use the GitX) after you update and prune all of your remote and local repository branches as below:

git remote update --prune

Then, create a new local branch for tracking this remote branch.

git checkout -b feature/mainpage-implementation-code-review --track origin/feature/mainpage-implementation

At this step, we can distinguish two of these branches by adding code-review word follow our local branch name, like this:

: feature/mainpage-implementation-code-review

It can help us to know: that is a branch which I want to do for code review.

After that, reset this branch to develop branch.

git reset develop

And you can see the changes between develop and feature/mainpage-implementation branches.

Next step, using Xcode to open your project.

Find the “Show only files with source-control status” icon on the bottom of left in your project file directory.

Now, you can see the files which be changed between these two branches in the project file directory.

Select a file which you want to review, and press the “Comparison” icon on the top of right in Xcode.

Then you can start to do a deeply code review line by line. 😎

Also, you can switch the “base comparison point” you want to compare.

For example, my left base comparison point is “Local Revision”, which meanings the changes on my feature/mainpage-implementation (code-review) branch.

On the right base comparison point is “27/5/2017 Henry Fan 23227e7 (HEAD)”, which meanings the last changes before feature/mainpage-implementation (code-review) branch.

And you can switch to another base comparison point to see the wonderful changes at different timing. ❤️

Btw, you should be done code review for “.xib” xml file too. 😋 (?)

There are some good points by using this way to do code review:

  • You can see the more clearly code changes in the whole file.

— Sometimes, on the gitHub review mode, it’s a little hard to know the whole relationship between your new change parts and original parts.

  • You can trace your codes more convenience.

— You can easily trace the whole flows and jump to the specific functions by using “command + left click of mouse” through in the whole project.

Actually, there are lots of code review ways you can choose, and all of them have different advantages and disadvantages.

So the most important thing is trying to discuss and find a good collaboration way with your coworkers.

The mainly goal is making your team’s workflow more smoothly. 😊

Btw, I found the “bitbucket” code review mode is same as Xcode comparison function, really cool. 😋

--

--

HAO-TI, FAN
Tech@Travelstart

看起來還是屁孩的 iOS 工程師、介面設計師、思考發想者;平時喜歡穿梭於字裡行間,擺動身體,在不同時空下創作影片;時而冒出天馬行空的想法,用點子串聯人。