root/apps/iphone/superbook/trunk/Classes/NSArray+FriendsSortCategory.m
@
738
| Revision 363, 2.7 kB (checked in by henri, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | // |
| 2 | // NSArray+FriendsSortCategory.m |
| 3 | // LocateThem |
| 4 | // |
| 5 | // Created by Henri Asseily on 8/18/08. |
| 6 | /* |
| 7 | Copyright (c) 2008-2009, Telnic Ltd. All rights reserved. |
| 8 | |
| 9 | Redistribution and use in source and binary forms, with or without modification, |
| 10 | are permitted provided that the following conditions are met: |
| 11 | |
| 12 | Redistributions of source code must retain the above copyright notice, this list of conditions |
| 13 | and the following disclaimer. Redistributions in binary form must reproduce the above copyright |
| 14 | notice, this list of conditions and the following disclaimer in the documentation and/or other |
| 15 | materials provided with the distribution. |
| 16 | Neither the name of the Telnic Ltd. nor the names of its contributors may be used to endorse or |
| 17 | promote products derived from this software without specific prior written permission. |
| 18 | THIS DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
| 19 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
| 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 24 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | // |
| 28 | |
| 29 | #import "NSArray+FriendsSortCategory.h" |
| 30 | |
| 31 | |
| 32 | @implementation NSArray ( FriendsSortCategory ) |
| 33 | |
| 34 | - (NSComparisonResult)distanceSortAlgorithm:(NSArray *)otherArray { |
| 35 | // The special comparison method gives highest value to the lowest section number |
| 36 | // and within that section, it compares the distances in km |
| 37 | // For example, if a person is 12,345 meters away and is in the first section (0) of people with .tel and a loc record, |
| 38 | // you get a value of 0*100,000+12,345/1000 = 12 |
| 39 | // For someone 20,000,000 meters away (probably the max on Earth), you get a value of 20,000 which is less than the value |
| 40 | // for someone without a LOC record (100,000) |
| 41 | |
| 42 | NSInteger a = [[self objectAtIndex:1] intValue] * 100000 + [[self objectAtIndex:4] intValue]/1000; |
| 43 | NSInteger b = [[otherArray objectAtIndex:1] intValue] * 100000 + [[otherArray objectAtIndex:4] intValue]/1000; |
| 44 | if (a < b) |
| 45 | return NSOrderedAscending; |
| 46 | else if (a > b) |
| 47 | return NSOrderedDescending; |
| 48 | else |
| 49 | return NSOrderedSame; |
| 50 | } |
| 51 | |
| 52 | - (NSComparisonResult)compositeNameSortAlgorithm:(NSArray *)otherArray { |
| 53 | return [[self objectAtIndex:0] localizedCompare:[otherArray objectAtIndex:0]]; |
| 54 | } |
| 55 | |
| 56 | @end |
Note: See TracBrowser
for help on using the browser.








