-
Notifications
You must be signed in to change notification settings - Fork 0
/
SFDDrawableInfo_LinkBack.m
75 lines (57 loc) · 1.78 KB
/
SFDDrawableInfo_LinkBack.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// SFDDrawableInfo_LinkBack.m
// K2LinkBackSupport
//
// Created by King Chung Huang on 3/12/05.
// Copyright 2005, 2007 King Chung Huang. All rights reserved.
//
#import "SFDDrawableInfo_LinkBack.h"
#import <LinkBack/LinkBack.h>
@implementation SFDDrawableInfo (LinkBack)
static NSMutableDictionary *_linkBackDataByInfo = nil;
static NSMutableDictionary *_linkBackKeysByInfo = nil;
+ (NSMutableDictionary *)_linkBackDataByInfo {
if (_linkBackDataByInfo == nil) {
_linkBackDataByInfo = [[NSMutableDictionary alloc] initWithCapacity:128];
}
return _linkBackDataByInfo;
}
+ (NSMutableDictionary *)_linkBackKeysByInfo {
if (_linkBackKeysByInfo == nil) {
_linkBackKeysByInfo = [[NSMutableDictionary alloc] initWithCapacity:128];
}
return _linkBackKeysByInfo;
}
- (void)deallocLinkBack {
[self setLinkBackData:nil];
[self setLinkBackKey:nil];
}
- (BOOL)hasLinkBackData {
return ([self linkBackData] != nil);
}
- (id)linkBackData {
return [[[self class] _linkBackDataByInfo] objectForKey:[self linkBackKey]];
}
- (void)setLinkBackData:(id)data {
if (data != nil) {
[[[self class] _linkBackDataByInfo] setObject:data forKey:[self linkBackKey]];
} else {
[[[self class] _linkBackDataByInfo] removeObjectForKey:[self linkBackKey]];
}
}
- (NSString *)linkBackKey {
NSString *key = [[[self class] _linkBackKeysByInfo] objectForKey:[NSString stringWithFormat:@"%u", (unsigned)self]];
if (key == nil) {
key = LinkBackUniqueItemKey();
[self setLinkBackKey:key];
}
return key;
}
- (void)setLinkBackKey:(NSString *)key {
if (key != nil) {
[[[self class] _linkBackKeysByInfo] setObject:key forKey:[NSString stringWithFormat:@"%u", (unsigned)self]];
} else {
[[[self class] _linkBackKeysByInfo] removeObjectForKey:[NSString stringWithFormat:@"%u", (unsigned)self]];
}
}
@end