UnderstandingIPhone DevelopmentAboutNSMutableArray sortingThe instance is the content to be introduced in this article, mainly to understandNSMutableArrayOfSortOperation, the content is not much, mainly based on the Code implementation content, look at the detailed code.
- -(NSArray *) sortedArrayUsingSelector :( SEL) comparator
-
- Parameters
- Comparator
-
- A selector that identifies the method to use to compare two elements at a time. The method shoshould returnNSOrderedAscending
- If the specified er is smaller than the argument, NSOrderedDescending if the specified er is larger than the argument,
- And NSOrderedSame if they are equal
- NSArray * sortedArray =
-
- [AnArray sortedArrayUsingSelector: @ selector (caseInsensitiveCompare :)];
- @ Property (nonatomic, readwrite, retain) NSMutableArray * parameters;
- [Self. parameters sortUsingSelector: @ selector (compare :)];
- # Pragma mark-
-
- -(NSComparisonResult) compare :( id) inObject {
- NSComparisonResult result = [self. name compare: [(MPURLRequestParameter *) inObject name];
- If (result = NSOrderedSame ){
- Result = [self. value compare: [(MPURLRequestParameter *) inObject value];
- }
- Return result;
- }
-
- SortedArrayUsingFunction: Applicable to basic types that support the compare method)
-
- # Pragma mark SORT METHOTDS
- NSInteger sortObjectsByLatestTime (id obj1, id obj2, void * context)
- {
- NSDate * d1 = [(MessageGroup *) obj1 latestTime];
- NSDate * d2 = [(MessageGroup *) obj2 latestTime];
- // Sort by desc
- Return [d2 compare: d1];
- }
- NSInteger dateSort (id obj1, id obj2, void * context)
-
- {
- NSDate * d1 = (Inbox *) obj1). datetime;
- NSDate * d2 = (Inbox *) obj2). datetime;
- Return [d1 compare: d2];
- }
-
- -(NSArray *) sortedMessages
- {
- Return [[groupMessages allValues] sortedArrayUsingFunction: sortObjectsByLatestTime context: NULL];
- }
-
- SortUsingDescriptors: Suitable for the dict type. initWithKey is both the dict key.
-
- NSMutableArray * regions = [NSMutableArray array];
- NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @ "name" ascending: YES];
- NSArray * sortDescriptors = [NSArray arrayWithObject: sortDescriptor];
- [Regions sortUsingDescriptors: sortDescriptors];
- [SortDescriptor release];
Summary: UnderstandingIPhone DevelopmentAboutNSMutableArray sortingThe instance content has been introduced. I hope this article will help you!