Home    |    Articles    |    Talks
—————————————————————————————————————————————

Why You Should Be Using `unowned` More Often

I’ve seen a lot of interesting codebases in the last two months: new clients of Industrial Binaries, submissions for my iOS Code Review series, and also code challenges of the candidates we’re recruiting.

I was surprised how rarely unowned is used in the wild.

Weak everywhere

I think this is a huge missed opportunity. Not using unowned in the right places makes the code harder to maintain and can hide some serious and hard-to-replicate errors.

Continue reading ...>

Mocking Network Calls Using URLProtocol

For many apps, the networking code is one of the most important parts of the whole codebase. Yet it’s also a part which is quite difficult to test properly.

Some people just give up and rely on thorough manual testing. This approach doesn’t really scale well. A medium-sized app can have hundreds of various API requests. Having to test all of them manually makes any future changes and refactoring tedious and dangerous.

URLProtocol Xcode screenshot

Another popular solution you can see in the wild is making real network calls, especially in integration and UI tests. Not great, not terrible ☢️.

Real network calls make tests simple but slower by the order of several magnitudes. It also makes them much less reliable. The success of the tests depends on your current network conditions. Ask yourself if it’s OK that your tests fail when the train you’re working from enters a tunnel.

Can we somehow keep the simplicity of real network calls while making it more reliable and network-conditions independent?

Continue reading ...>

iOS Code Review #1: A Simple Weather App

I decided to try something new and recorded a YouTube video. This is the first video of the iOS Code Review series I’d like to do. In this series I’m going to review iOS projects which you can submit using this form.

I’ll remove all traces of the author or name of the project from the codebase. I’d like to focus solely on the code and show how to improve problematic parts.

Submit a project to the next iOS code review using https://vojtastavik.typeform.com/to/Y5p1BU.

Advanced testing using `Behavior` in Quick

Behavior<Context> is a hidden gem in the Quick testing framework. It was introduced silently in 2017 and it’s not even mentioned in the documentation! Here’s my PR which fixes that. The more I know about it the more I think this should be the way we write specs in Quick.

Behavior Xcode screenshot

So, what’s Behavior? You can think of it as of a better and safer way of defining shared expectation. But that would be very shortsighted. There’s much more!

Continue reading ...>

Simple XCTest Log Formatter in Swift

The raw output from xcodebuild is very detailed and hard to read. The community go-to tool for fixing this is xcpretty. Unfortunately, it happens to me regularly, that the formatted log xcpretty produces doesn’t contain the details I consider important. For example, I’d like to see the raw console output when a test case fails.

xcpretty example

I realized recently that I tend to build more and more parts of the tooling I need myself. Especially, when the functionality I usually need is trivial, and writing scripts in Swift is so easy! So I decided to write my own XCTest log formatter; because why not?

Continue reading ...>

Fastlane + Travis + TestFlight Tutorial

This blog post is different from other ones. I write it mostly for my future self. I worked on setting up the CI pipeline for a new project recently. If you’ve ever done it, you know it’s usually a painful experience.

The biggest problem is that this kind of work is not something an average developer would do every week; not even every month. I write this blog post to capture my experience so I have a step-by-step tutorial to use in the future.

Continue reading ...>

Building an iOS App Without Xcode's Build System

A build system, despite its scary-sounding name, is just a regular program, which knows how to build other programs. As an iOS developer, you’re certainly familiar with how to build a project using Xcode. You go to the Product menu and select Build, or you use the ⌘B keyboard shortcut.

You may have also heard about Xcode Command Line Tools. It’s a set of tools which allows you to build Xcode projects directly from the terminal using the xcodebuild command. A very convenient thing for automating your processes, for example on your CI.

Build System

No matter how you’ve initiated it, the building itself is orchestrated by Xcode’s build system.

Can we replicate the building process and build the app “manually”, without Xcode’s build system?

Is it possible to sign the resulting app? Or even deploy it to an actual iOS device?

Continue reading ...>

What's inside the Derived Data folder?

Deleting derived data - a well know trick that comes in handy every time Xcode behaves strangely for no obvious reason. I still clearly remember when my senior told me about this basic iOS dev trick for the first time.

Derived Data folder

As years went by, and with more experience gained, I started to understand what kind of errors can be fixed like that. However, I never really understood what exactly is inside the DerivedData folder. I decided to change that and here are my findings.

Continue reading ...>