Welcome

I recently moved the blog from Blogger into this ghost-based new home. Some things are still work in progress, let me know if you find something in need of attention. a-coding is mostly about my programming insights. I'll post here every time I come up with a clever or particularly…

Defer in Objective-C

Some time ago I was learning Go and I came across a very useful feature: defer. As its name suggests it defers the execution of a piece of code until the current function returns. defer is very useful when dealing with resources or locks. For example suppose you have a…

Simplifying UIKit Animations

If you have ever worked with animations in iOS using UIKit you have most likely ended up with nested animation blocks and intractable code at some point. One of the problems that comes up is trying to chain multiple animations. You want animation B to run only after animation A…

Delegate Multiplexing

I have mentioned before how Cocoa is biased towards the delegate pattern. I argued that in some instances the observer pattern would be better suited. But in some cases the delegate pattern is the way to go. Something you could argue as a limitation of the delegate pattern is the…

A* data structures

A* (A-star) is the typical textbook algorithm: it is a simple concept and can be easily explained. It is also widely known, one of the first algorithms you learn in AI. But for some reason it is rarely implemented properly. A* does a graph search minimizing the node expansions, therefore…

Predictive Collision Detection

On certain applications, specially games, it is often necessary to determine if two moving objects collide. The standard approach is to check for overlap after each step of the animation. While this approach may be sufficiently accurate for some applications, sometimes you need to determine the exact point of collision…