• Using DDHTweaks To Find Perfect Values

    Sometimes you may wish you could tweak some values of your app (colors, font sizes, text) while you test it in the field. Or you would like to enable a feature to test it but don’t like to show that feature to your beta testers yet.

    With my framework DDHTweaks you can do exactly this. You just need to add a bit of code to be able to change some values while the app runs.


  • Testing the User Interface with FBSnapshotTestCase

    Sometimes you need to add automatic tests for the UI of your app. There are several different approaches to achieve this.

    In the test you could get the elements of the screen and assert if all the frames are as you expect. Depending on the UI you want to test, this can be a lot of work.

    Or you could use UI tests provided by Xcode. But those are extremely slow and in my experience sometimes they just stop working.

    There is a better alternative. Facebook has an open source component called FBSnapshotTestCase. This class allows you create snapshot tests. A snapshot test compares the UI of a view with a snapshot of how the view should look like. Let’s see how this works.


  • Creating a "smart" Xcode file template

    Did you know that you can create your own file templates for Xcode? Sure you did. But did you also know that you can create a template that takes a string and puts it into a field you define?

    Let’s build a file template for a Swift protocol and a protocol extension.

    Create a file template

    First things first.

    Xcode looks for your custom templates at the location ~/Library/Developer/Xcode/Templates/. We will start by copying a template that comes with Xcode to that location.


  • 4th Problem from Project Euler in Swift

    Yesterday I read this post by Joseph Jude. He experienced that Swift is way slower in solving the 4th problem from Project Euler when compared to Python and Typescript.

    The 4th problem in Project Euler is this:

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.


  • Using a Playground instead of Keynote

    Yesterday I gave a talk at the Cologne Swift meetup and I tried something new. I used a Swift Playground for the “Slides”.

    Functions - Basics I.xcplaygroundpage 2016-04-22


  • What to learn first

    Yesterday I got asked, what a Swift beginner should learn first. Here is the question:

    I did want to ask you something, is it worth a while to learn TDD, or spend that time learning Swift, and functional programming?

    Of course, my opinion is a bit biased as I wrote a book about TDD with Swift. So, keep that in mind when you read my answer.

    Advice #1: Read the Swift Book provided by Apple.

    In my opinion you should first learn Swift. This is the basis of everything. If you don’t understand what functions can do in Swift, you won’t understand the concepts of functional programming in Swift. In addition, Swift is still mainly used to write apps for iOS and OS X. This means, most of the time you need to interact with object oriented APIs (at least at the time of writing ;)). So you also need to understand object oriented Swift to leverage the potential of Swift when writing Swift.

    And even if you don’t believe me, this is what Chris Eidhof, Florian Kugler, and Wouter Swierstra write in Functional Swift:

    „You should be comfortable reading Swift programs and familiar with common programming concepts, such as classes, methods, and variables. If you’ve only just started to learn to program, this may not be the right book for you.“


  • #selector() and the responder chain

    With the new syntax for selectors in Swift 2.2 the approach I used in “Utilize the responder chain for target action” produces a warning. Let’s fix that.

    Protocols for president

    First we add a protocol:

    @objc protocol DetailShowable {
      @objc func showDetail()

    Then we can add an extension to Selector as described in this awesome post by Andyy Hope that looks like this:

    private extension Selector {
      static let showDetail = #selector(DetailShowable.showDetail)

  • Feedback to "The best table view controller"

    I got some feedback to my last blog post about The best table view controller. In this post I want to comment on the feedback because the comment sections is not really good for detailed discussion.


    I couldn’t get Interface Builder in Xcode 7.3 to support typed view controllers. While you can type in the associated class, the field becomes blank when the storyboard is saved.

    Interesting. I wasn’t aware of this. But this again tells me, that storyboards (and the Interface Builder in general) are not suited for my style of iOS development. As you may know, I don’t like the Interface Builder.

    If you depend on storyboards for your User Interface, than this kind of table view controller isn’t for you (yet).


  • The best table view controller (Mar 2016 edition)

    Since I read the objc.io post about light view controller, every few month I come back to the same problem: find the best way to write a table view controller. I have tried several different approaches like putting the data source and delegate in a separate class or using MVVM to populate the cell.

    This post is the March 2016 solution to this problem. And as most of the times, I’m quite happy with the current solution. It uses generics, protocols and value types.

    The main part is the base table view controller. It holds the array to store the model data, is responsible for registering the cell class and it implements the needed table view data source methods.

    Let’s start with the class declaration:

    import UIKit
    class TableViewController<T, Cell: UITableViewCell where Cell: Configurable>: UITableViewController {

  • Testing Push Onto The Navigation Stack

    Last month my book about Test-Driven Development with Swift finally got published. In this and some of the next blog posts I will present some things I learned while I wrote it.

    In this post I will show a nice way to test if a view controller got pushed onto the navigation stack as a result of an event.

    Let’s say we have button on a view controller. When the user taps the button, a detail view controller should be pushed onto the navigation stack. How can we test this?

    Easy! We will use a mock for the navigation controller. The mock looks like this:

    class MockNavigationController: UINavigationController {
      var pushedViewController: UIViewController?
      override func pushViewController(viewController: UIViewController, animated: Bool) {
        pushedViewController = viewController
        super.pushViewController(viewController, animated: true)

subscribe via RSS