Hi all,
Program 15:13 gives an example of sorting an array, using the "sortUsingSelector" method. Because the array contains, as it's elements, AddressCards, ( which in turn contain 2 NSStrings), the "selector" chosen ( defined below) compares two NSStrings.
Some questions have arisen, which I would like to pose to the group.
Question 1: (Somewhat Indirectly associated with p 363).
This is clearly ( well, I hope clearly) different from a **sorted** array, but how. Does "ordered" refer to the sequential allocation of elements?
Question 2: About the middle of the page:
Last Question ( all these damned question!!!! )
The defintion for the compare method is thus.
Why is "element" declared as type (id)?. Is this a requirement of the compare method of NSString? The name "element" is unique, or just an identifier chosen by the programmer.
thanks as usual
Program 15:13 gives an example of sorting an array, using the "sortUsingSelector" method. Because the array contains, as it's elements, AddressCards, ( which in turn contain 2 NSStrings), the "selector" chosen ( defined below) compares two NSStrings.
Some questions have arisen, which I would like to pose to the group.
Question 1: (Somewhat Indirectly associated with p 363).
(Collections Programming Topics for Cocoa, Apple documentation).Arrays are ordered collections that can contain any sort of object
This is clearly ( well, I hope clearly) different from a **sorted** array, but how. Does "ordered" refer to the sequential allocation of elements?
Question 2: About the middle of the page:
If one compares this to a description of the term Comparator in "sortUsingSelector"When it needs to make such a comparison, it invokes the specified method, sending the message to the first element in the array (the receiver) to be compared against it's argument
then I wonder if I am being nitpicky, or whether I am missing something here. In other words, the more generic description allows the compiler (??) to choose a quicksort/bubblesort etc, ie it does not decide **how** to sort, it simply says **sort these two things**The comparator message is sent to each object in the receiver and has as its single argument another object in the array.
Last Question ( all these damned question!!!! )
The defintion for the compare method is thus.
Code:
-(NSComparisonResult) compareNames: (id) element
{
return [ name compare: [element name] ]
}
Why is "element" declared as type (id)?. Is this a requirement of the compare method of NSString? The name "element" is unique, or just an identifier chosen by the programmer.
thanks as usual