Created
May 17, 2012 16:19
-
-
Save pita5/2719952 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.dataSource = [self.dataSource sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { | |
Comment *comment1 = obj1; | |
Comment *comment2 = obj2; | |
if (comment1 == comment2) | |
{ | |
return NSOrderedSame; | |
} | |
// check if both are top level | |
if (comment1.replyto == nil && comment2.replyto == nil) | |
{ | |
return [comment1.viewCount compare:comment2.viewCount]*-1; | |
} | |
else if (comment1.replyto != nil && comment2.replyto == nil) | |
{ | |
Comment *root1 = [self rootComment:comment1]; | |
if (root1 == comment2) | |
{ | |
return NSOrderedDescending; | |
} | |
else | |
{ | |
return [root1.viewCount compare:comment2.viewCount]*-1; | |
} | |
} | |
else if (comment1.replyto == nil && comment2.replyto != nil) | |
{ | |
Comment *root2 = [self rootComment:comment2]; | |
if (root2 == comment1) | |
{ | |
return NSOrderedAscending; | |
} | |
else | |
{ | |
return [comment1.viewCount compare:root2.viewCount]*-1; | |
} | |
} | |
else | |
{ | |
Comment *root1 = [self rootComment:comment1]; | |
Comment *root2 = [self rootComment:comment2]; | |
if (root1 == root2) | |
{ | |
return [comment1.pubdate compare:comment2.pubdate]; | |
} | |
else | |
{ | |
return [root1.viewCount compare:root2.viewCount]*-1; | |
} | |
} | |
return NSOrderedSame; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment