3Blocks

One shortcoming of C and Objective-C is code that performs a particular task becomes scattered around the code base. Say you are performing an operation on a C array of People structs and you need to sort the list by last name. Luckily, there is the library function qsort() to sort the array. qsort() is well-optimized and does its job well, but it needs some help. It does not know how items are compared to each other so that they end up in the proper sorted order.

.​.​.​ q​s​o​r​t​ ​(​p​e​o​p​l​e​A​r​r​a​y​,​ ​c​o​u​n​t​,​ ​s​i​z​e​o​f​(​P​e​r​s​o​n​)​,​ ​p​e​r​s​o​n​N​a​m​e​C​o​m​p​a​r​e​)​;​ .​.​.​ i​n​t​ ​p​e​r​s​o​n​N​a​m​e​C​o​m​p​a​r​e​ ​(​c​o​n​s​t​ ​v​o​i​d​ ​*​t​h​i​n​g​1​,​ ​c​o​n​s​t​ ​v​o​i​d​ ​*​t​h​i​n​g​2​)​ ​{​ ​ ​ ​ ​P​e​r​s​o​n​ ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.