Why NSNotificationCenter is Bad

Bullhorn

A lot of talk about good coding practices centers around the idea of loose coupling. That is, writing classes that interact based on behavior, not by identity. If class A needs to interact with class B, it should do so on the basis of what class B does, not because of what it is. That way we can easily swap out class B for another one that behaves the same and not worry about breaking class A. This makes our applications easier to maintain and update. Continue reading

How to Swap Two Variables Without Using a Temp Variable

swap

With all the high-level languages in widespread use today, it is often easy to forget that at the end of the day, everything boils down to binary: ones and zeroes. This is shielded from us via multiple layers of abstraction. There is nothing wrong with using these abstractions; they have made great modern-day development possible. At the same time, they conceal some of the more intriguing quirks that are inherent in the binary system. This includes bitwise operations, and specifically an operation called a bitwise swap. This is a very efficient operation that can exchange the values of two variables of the same type without using an intermediary variable, and looks like this in C:

Continue reading

The Great Pointer Syntax Debate

Asterisk

In Objective-C and other C-based languages, pointers are declared using the asterisk character. So, to declare a pointer to a UIView object called foo, in most examples and documentation you will see:

Continue reading