Skip to content

Commit

Permalink
- update recent
Browse files Browse the repository at this point in the history
  • Loading branch information
tue-savvy committed Oct 9, 2014
1 parent fc645f6 commit 69274f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SimulatorManager/RecentAppsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

#import <Foundation/Foundation.h>

FOUNDATION_EXPORT NSString *const RecentAppUpdateNotification;

@class Simulator;
@class SimulatorApp;
@interface RecentAppsManager : NSObject
Expand Down
10 changes: 10 additions & 0 deletions SimulatorManager/RecentAppsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

#define RecentAppsKey @"RecentApps"
#define MAX_RECENT 5


NSString *const RecentAppUpdateNotification = @"RecentAppUpdateNotification";


@interface RecentAppsManager()
@property (nonatomic, strong) NSMutableArray *recentData;
@property (nonatomic, strong) NSMutableArray *recentSimulatorApps;
Expand Down Expand Up @@ -46,6 +51,8 @@ - (void)addRecentApp:(SimulatorApp *)app {
NSInteger index = 0;
for (NSDictionary *recentDict in self.recentData) {
if ([recentDict[@"SimulatorPath"] isEqual:simulatorPath] && [recentDict[@"AppPath"] isEqual:appPath]) {
if (index == 0) return;

//move recent to first position
[self.recentData removeObject:recentDict];
[self.recentData insertObject:recentDict atIndex:0];
Expand All @@ -56,6 +63,7 @@ - (void)addRecentApp:(SimulatorApp *)app {

[[NSUserDefaults standardUserDefaults] setObject:self.recentData forKey:RecentAppsKey];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:RecentAppUpdateNotification object:self];
return;
}
index++;
Expand All @@ -76,6 +84,8 @@ - (void)addRecentApp:(SimulatorApp *)app {
[[NSUserDefaults standardUserDefaults] setObject:self.recentData forKey:RecentAppsKey];
[[NSUserDefaults standardUserDefaults] synchronize];

[[NSNotificationCenter defaultCenter] postNotificationName:RecentAppUpdateNotification object:self];

}

- (NSArray *)recentApps {
Expand Down

0 comments on commit 69274f3

Please sign in to comment.