Skip to content

Instantly share code, notes, and snippets.

@lwansbrough
Created July 10, 2015 06:16
Show Gist options
  • Select an option

  • Save lwansbrough/4e633f2d5faec70904d3 to your computer and use it in GitHub Desktop.

Select an option

Save lwansbrough/4e633f2d5faec70904d3 to your computer and use it in GitHub Desktop.
//
// 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
//
// 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