Latest Tweets:

A category for positioning UIView with ease.

Let’s take the code below:

CGRect rect = button.frame;
rect.origin.x = tableView.frame.origin.x;
rect.origin.y = tableView.frame.origin.y + tableView.frame.size.height;
button.frame = rect;

Assuming button and tableView are in the same superview, the code aligns button just below tableView and to the left. That’s grand, but there’s a lot of boilerplate code around and if you’re not using nib files, you’ll be writing a lot of code like this. Actually, even if you do use nib files you’ll probably going to write this stuff often enough to become a nuisance.

Read More

sizeof(char) is always 1 but should be considered good practice

I stumbled upon this post today, and while the author did some very good remarks:

char i;
size_t iSize = sizeof i;

it’s easier to maintain and read than:

char i;
size_t iSize = sizeof(char);

I’m outraged sadden by his belief that since sizeof(char) (or sizeof i in our first example) is always 1 as per C standard we should always write code like this:

aChar = malloc(kCharsCount);

instead of:

aChar = malloc(kCharsCount*sizeof(*aChar));
//aChar = malloc(kCharsCount*sizeof(char)); as he puts it

Because, “It adds clutter and it suggests that you don’t know enough C”. That’s utterly rubbish.

Read More

*1

How to set breakpoints for specific functions/methods using LLDB command line

The motivation

Let’s say that during debugging you want to pause execution every time a view will appear in an iOS app (viewWillAppear) and you have so many controllers that adding the breakpoints manually would be cumbersome.

Read More

A simple way to set up GLKView without the Xcode template

The motivation

Xcode’s OpenGL Game template is not quite the cleanest way to start your OpenGL project. It adds a lot of code you don’t initially need and by the time you will need it, you’ll probably structure it in a different manner, which means you’ll have to clean it form the template.

The good news is that, to set up the most basic GLKView to handle your drawing routines you only need 3 lines of code.

The example project for this article can be found here

Read More

Advanced delegation. A decorator design pattern example.

The motivation

You probably wrote the following lines in your view controllers plenty of times:

self.tableView.delegate = self;
self.tableView.dataSource = self;

Usually, that’s fine.

However, if you have another table view in your app which has more or less the same look and feel, but a different controller managing it, a problem rises.

It would be nice to reuse all the delegation code you wrote in your initial controller. And only change the data and do other small customisations. You could tackle this problem in several ways.

But before we start, know that you can find the Github project for this article here.

Read More