You can do it like this:
- Create
NSArray *result
with the size of the combined arrays - Concatenate the two arrays into the
result
array by copying the elements of the first array followed by the elements of the second array into theresult
. - Use
sortedArrayUsingComparator:
with a comparator that "understands" both types.
Here is a skeletal implementation:
NSArray *sortedArray = [result sortedArrayUsingComparator: ^(id obj1, id obj2) {
NSString *key1, *key2;
if ([obj1 isKindOfClass:['class has a title' class]]) {
key1 = [obj1 title];
} else { // It's the kind of objects that has a name
key1 = [obj1 name];
}
if ([obj2 isKindOfClass:['class has a title' class]]) {
key2 = [obj2 title];
} else { // It's the kind of objects that has a name
key2 = [obj2 name];
}
// Do the comparison
return [key1 caseInsensitiveCompare:key2];
}];