From 5daa82b0ba47c8c887fa2adb1d68bf7201d083b3 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 13 Nov 2015 19:55:18 -0800 Subject: [PATCH] Show the hosts in alphabetical order rather than in an undefined order --- Limelight/Database/Host.h | 2 ++ Limelight/Database/Host.m | 4 ++++ Limelight/ViewControllers/MainFrameViewController.m | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Limelight/Database/Host.h b/Limelight/Database/Host.h index d866676a..89968ace 100644 --- a/Limelight/Database/Host.h +++ b/Limelight/Database/Host.h @@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) PairState pairState; @property (nonatomic) NSString * activeAddress; +- (NSComparisonResult)compareName:(Host *)other; + @end NS_ASSUME_NONNULL_END diff --git a/Limelight/Database/Host.m b/Limelight/Database/Host.m index 133f0164..d1153116 100644 --- a/Limelight/Database/Host.m +++ b/Limelight/Database/Host.m @@ -14,4 +14,8 @@ @synthesize online; @synthesize activeAddress; +- (NSComparisonResult)compareName:(Host *)other { + return [self.name caseInsensitiveCompare:other.name]; +} + @end diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index f259dde4..3eb2cdcb 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -640,7 +640,9 @@ static NSMutableSet* hostList; UIComputerView* compView; float prevEdge = -1; @synchronized (hostList) { - for (Host* comp in hostList) { + // Sort the host list in alphabetical order + NSArray* sortedHostList = [[hostList allObjects] sortedArrayUsingSelector:@selector(compareName:)]; + for (Host* comp in sortedHostList) { compView = [[UIComputerView alloc] initWithComputer:comp andCallback:self]; compView.center = CGPointMake([self getCompViewX:compView addComp:addComp prevEdge:prevEdge], hostScrollView.frame.size.height / 2); prevEdge = compView.frame.origin.x + compView.frame.size.width;