-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeakMutableArray.m
50 lines (41 loc) · 1013 Bytes
/
WeakMutableArray.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
//
// WeakMutableArray.m
// TestDemo
//
// Created by xiao xu on 2021/4/14.
//
#import "WeakMutableArray.h"
@interface WeakMutableArray ()
@property (nonatomic, strong) NSPointerArray *pointerArray;
@end
@implementation WeakMutableArray
- (instancetype)init {
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
self.pointerArray = [NSPointerArray weakObjectsPointerArray];
}
- (void)addObject:(id)object {
[self.pointerArray addPointer:(__bridge void *)(object)];
}
- (id)objectAtWeakMutableArrayIndex:(NSUInteger)index {
return [self.pointerArray pointerAtIndex:index];
}
#pragma mark - 重写getter方法
@synthesize allObjects = _allObjects;
- (NSArray *)allObjects {
return self.pointerArray.allObjects;
}
@synthesize usableCount = _usableCount;
- (NSInteger)usableCount {
return self.pointerArray.allObjects.count;
}
@synthesize allCount = _allCount;
- (NSInteger)allCount {
return self.pointerArray.count;
}
@end