Created
July 10, 2015 06:16
-
-
Save lwansbrough/4e633f2d5faec70904d3 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
| // | |
| // ObjectStore.h | |
| // | |
| // Created by Lochlan Wansbrough on 2015-06-06. | |
| // Copyright (c) 2015 Facebook. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface ObjectStore : NSObject | |
| @property (nonatomic, strong) NSMutableDictionary *references; | |
| + (id)shared; | |
| - (id)getObject:(NSString *)uuid; | |
| - (NSString *)putObject:(id)objectId; | |
| - (void)removeObject:(NSString *)uuid; | |
| @end |
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
| // | |
| // ObjectStore.m | |
| // | |
| // Created by Lochlan Wansbrough on 2015-06-06. | |
| // Copyright (c) 2015 Facebook. All rights reserved. | |
| // | |
| #import "ObjectStore.h" | |
| @implementation ObjectStore | |
| + (id)shared { | |
| static ObjectStore *sharedObjectStore = nil; | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ | |
| sharedObjectStore = [[self alloc] init]; | |
| }); | |
| return sharedObjectStore; | |
| } | |
| - (id)init { | |
| if (self = [super init]) { | |
| self.references = [NSMutableDictionary dictionary]; | |
| } | |
| return self; | |
| } | |
| - (id)getObject:(NSString *)uuid { | |
| return [self.references valueForKey:uuid]; | |
| } | |
| - (NSString *)putObject:(id)objectId { | |
| NSString *uuid = [[NSUUID UUID] UUIDString]; | |
| [self.references setValue:objectId forKey:uuid]; | |
| return uuid; | |
| } | |
| - (void)removeObject:(NSString *)uuid { | |
| [self.references removeObjectForKey:uuid]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment