Using Swift’s String Type With Care

Recently, a friend of mine asked me to teach him some Swift following the news of the language going open source. I have grabbed the latest Xcode 7 beta 2 and went ahead with a mission to remind myself a syntax and try out the latest Swift 2 additions. Inspired by Protocol-Oriented Programming WWDC session I decided to build a protocol-oriented diff tool for various types of files.

To be able to perform diff for text files one have to solve longest common subsequence problem first. There is an excellent article about the topic on Word Aligned. I will not go any deeper into that, since it is not required to understand the post. Because I did not want to waste too much time building the algorithm myself, I decided to use premade one from Rosetta Code. I quickly ported it to Swift 2, made it into String extension and run the tests to see whether it performs as expected.

Since I was using a dynamic programming solution the complexity class of the algorithm should be $O(n^2$). Surely my computer is powerful enough to handle this, isn’t it? I have generated two random strings of 500 characters each, ran the tests and… could not believe my eyes. The code wrapped in XCTest’s measureBlock: took 8.899 seconds to find the solution. What went wrong?

Read on →

iOS Unit-Test Recipes: UIViewControllers

Having little to no experience in TDD it is easy to overlook the possibility to verify view controller’s behavior. Today I am going to share few recipes for testing scenarios I stumbled upon when working on my own project. I believe the below list is general enough to make it to almost any app:

  1. Transitions between controllers (whether it took place).
  2. Passing arguments between controllers.
  3. Alerts.
  4. Asynchronous method calls.
Read on →

iOS Unit-Test Recipes: Singletons

How many times have you seen a source code similar to this?

- (BOOL)shouldShowLicenseAgreement {
  static NSString* key = @"ShouldShowLicenseAgreement";
  NSNumber* showLicense = [[NSUserDefaults standardUserDefaults] objectForKey:key];

  if (showLicense != nil) {
      return [showLicense boolValue];

  return YES;

If you have been developing iOS applications for a while your answer is probably quite a lot. Yes, NSUserDefaults mechanism is really useful. However, the singleton pattern implemented by standardUserDefaults method is not, at least from unit-tests’ point of view.

Read on →

Gmail-like Avatar Mockup

Yesterday I stumbled upon a small task, which required a bit of conceptual work. I came out with a rather simple and efficient solution for the problem, which I want to share with the blog readers.

I was building a mobile application to manage BPM processes’ tasks. One of the core features was to present comments added by users. Because of very limited space inside a table view cell I decided to visualize author using a Gmail-inspired avatar with initials, which is presented below.

Gmail avatar example

Initially, the avatar’s background color was randomized each time a task’s details were fetched. This caused some problems with visual identity, because the color mapping was not permanent. Given the fact that the main system was unable to generate color schemes I had to come up with client-side solution.

Read on →


Following the path of personal development, me and my friend decided to have a small hackaton-like weekend. Working for about twelve hours straight for two days, we built a software which optimises food ordering process in companies. Our idea was to:

  • Have a source to deliver the data about nearby restaurants and their menus. The source publishes the data through REST webservices. For an initial data source, we have decided to develop simple django framework powered webpage. The webpage allows to input restaurant’s data through the django’s admin panel and publish data using django REST framework project.
  • The restaurants’ data is being received by a service developed in C#. Its main goal is to facilitate ordering process for any client software. The service publishes REST multipurpose-API for creating, joining and iterating over orders, viewing restaurants & dishes and so on.
  • Implement a sample client capable of creating and joining existing orders. For this purpose, we have introduced iOS client targeted for iPhone, with platform’s native interface.
  • Have as much fun as possible!
Read on →

Drill Down Image Navigation for IOS

Recently I have developed an application for iPad with a small, nifty feature. The data was a hierarchy of multiple objects ordered from the least to the most detailed one. Every top-level entity contained many lower-level entities. Taking advantage of this fact, the specification expected navigation to be implemented as a drill down through a series of images, each of them containing multiple clickable areas. The code had to fulfil two basic requirements:

  • to be as simple as possible,
  • to be as generic as possible.
Read on →

Simple Cloneable and Iterable Undirected Graph in Python

This semester I have decided to enroll to Graphs and Networks subject. My task was to implement tabu search algorithm for graph coloring problem. The project is currently underway, but it already contains useful source code for graph-related problems, which I decided to share with blog readers.

To kick things off, I have implemented a really simple graph structure. The structure had to satisfy following requirements:

  • Being suitable for undirected graphs only.
  • Being able to store information about vertex color.
  • Being iterable.
  • Being cloneable.
Read on →

Warsaw 19115

Today my first-ever piece of iOS software got finally published on AppStore. Warszawa 19115 is a small utility allowing Warsaw’s citizens to request an action from city hall staff whenever they feel it is necessary. The request can be composed utilizing a basic three-step workflow:

  1. Take a picture.
  2. Choose location from a map.
  3. Add a description.

Additionally, the app allows to share some thoughts on improving living standards in the city.

It is certainly not any sort of the state-of-the-art, pioneer and most technologically advanced application in the world, however it still feels nice to have some work done to serve multiple people. Hope everything runs smooth for you!