From Lecture 2 of iOS Stanford course Winter 2013 - card matching game