Instance Method インスタンスメソッド

sortedArrayUsingSelector:

Returns an array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by a given selector. ある配列を返します、それは受け手側の配列の持つ要素を昇順で列記します、与えられたセレクタによって指定される比較メソッドで決定されるとおりにです。

Declaration 宣言

- (NSArray<ObjectType> *)sortedArrayUsingSelector:(SEL)comparator;

Parameters パラメータ

comparator

A selector that identifies the method to use to compare two elements at a time. The method should return NSOrderedAscending if the receiving array is smaller than the argument, NSOrderedDescending if the receiving array is larger than the argument, and NSOrderedSame if they are equal. 2つの要素を同時に比較するために使うメソッドを識別するセレクタ。このメソッドは、受け手側の配列が引数より小さいならばNSOrderedAscendingを、受け手側の配列が引数より大きいならばNSOrderedDescendingを、そしてそれらが等しいならばNSOrderedSameを返さなければなりません。

Return Value 戻り値

An array that lists the receiving array’s elements in ascending order, as determined by the comparison method specified by the selector comparator. 新しい配列、それは、受け手側の配列の持つ要素を昇順で、セレクタcomparatorによって指定される比較メソッドで決定されるとおりに列記するものです。

Discussion 議論

The new array contains references to the receiving array’s elements, not copies of them. それらのコピーではなく、受け手側の持つ要素に対する参照を含んでいる新しい配列。

The comparator message is sent to each object in the array and has as its single argument another object in the array. comparatorメッセージは、配列の中の各オブジェクトに送られます、そしてそれのただ1つの引数として配列の中の別のオブジェクトを持ちます。

For example, an array of NSString objects can be sorted by using the caseInsensitiveCompare: method declared in the NSString class. Assuming anArray exists, a sorted version of the array can be created in this way: 例えば、NSStringオブジェクトからなるある配列は、NSStringクラスの中で宣言されるcaseInsensitiveCompare:メソッドを使うことによってソートされることができます。anArrayがあると仮定して、その配列のソートされたバージョンはこの方法で作成されることができます:


     NSArray *sortedArray =
         [anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

See Also 参照

Sorting ソートする