O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required