-
Notifications
You must be signed in to change notification settings - Fork 0
/
MutableDictionarySerialAdapter.m
43 lines (35 loc) · 1.15 KB
/
MutableDictionarySerialAdapter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// MutableDictionarySerialAdapter.m
// AlcoholScanner
//
// Created by Александр Поляков on 17.06.16.
// Copyright © 2016 AGIMA.mobile. All rights reserved.
//
#import "MutableDictionarySerialAdapter.h"
@interface MutableDictionarySerialAdapter ()
@property (nonatomic) dispatch_queue_t queue;
@property (strong, nonatomic) NSMutableDictionary *dictionary;
@end
@implementation MutableDictionarySerialAdapter
- (instancetype)init {
if (self = [super init]) {
self.queue = dispatch_queue_create("ru.agima.mobile.Objective-JNI-Environment.MutableDictionarySerialAdapterQueue", DISPATCH_QUEUE_SERIAL);
self.dictionary = [[NSMutableDictionary alloc] init];
}
return self;
}
- (id)objectForKey:(id)aKey {
__block id value;
__weak NSMutableDictionary *dictionary = self.dictionary;
dispatch_sync(self.queue, ^{
value = [dictionary objectForKey:aKey];
});
return value;
}
- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
__weak NSMutableDictionary *dictionary = self.dictionary;
dispatch_sync(self.queue, ^{
[dictionary setObject:anObject forKey:aKey];
});
}
@end