Problem: Program crashes when using NSArray's sortedArrayUsingFunction:context: Old code used qsort like this: id cells = [matrix itemList]; if (cells) { qsort(NX_ADDRESS(cells), [cells count], sizeof(id *), cellcmp); } And called this function: static int cellcmp(const void *first, const void *second) { const char *s1 = [*((id *)first) title]; const char *s2 = [*((id *)second) title]; return (s1 && s2) ? strcmp(s1, s2) : 0; } Newly ported code uses NSMatrix's sorting function: [matrix sortUsingFunction:celltitlecmp context:NULL]; And called this function (which crashed the program): static int celltitlecmp(id first, id second) { return [[first title] compare:[second title]]; } Solution: New function didn't prototype the compare function correctly, note that it needs a third, void *, parameter: static int celltitlecmp(id first, id second,void *userdata) { return [[first title] compare:[second title]]; } |