11
11
12
12
@interface BEMCheckBoxGroup ()
13
13
14
- @property (nonatomic , strong , nonnull ) NSOrderedSet <BEMCheckBox *> *checkBoxes;
14
+ @property (nonatomic , strong , nonnull ) NSHashTable *checkBoxes;
15
15
16
16
@end
17
17
18
18
/* * Defines private methods that we can call on the check box.
19
19
*/
20
20
@interface BEMCheckBox ()
21
21
22
- @property (weak , nonatomic , nullable ) BEMCheckBoxGroup *group;
22
+ @property (strong , nonatomic , nullable ) BEMCheckBoxGroup *group;
23
23
24
24
- (void )_setOn : (BOOL )on animated : (BOOL )animated notifyGroup : (BOOL )notifyGroup ;
25
25
@@ -31,7 +31,7 @@ - (instancetype)init {
31
31
self = [super init ];
32
32
if (self) {
33
33
_mustHaveSelection = NO ;
34
- _checkBoxes = [NSOrderedSet orderedSet ];
34
+ _checkBoxes = [NSHashTable hashTableWithOptions: NSPointerFunctionsWeakMemory ];
35
35
}
36
36
return self;
37
37
}
@@ -52,9 +52,8 @@ - (void)addCheckBoxToGroup:(nonnull BEMCheckBox *)checkBox {
52
52
53
53
[checkBox _setOn: NO animated: NO notifyGroup: NO ];
54
54
checkBox.group = self;
55
- NSMutableOrderedSet *mutableBoxes = [self .checkBoxes mutableCopy ];
56
- [mutableBoxes addObject: checkBox];
57
- self.checkBoxes = [NSOrderedSet orderedSetWithOrderedSet: mutableBoxes];
55
+
56
+ [self .checkBoxes addObject: checkBox];
58
57
}
59
58
60
59
- (void )removeCheckBoxFromGroup : (nonnull BEMCheckBox *)checkBox {
@@ -64,9 +63,7 @@ - (void)removeCheckBoxFromGroup:(nonnull BEMCheckBox *)checkBox {
64
63
}
65
64
66
65
checkBox.group = nil ;
67
- NSMutableOrderedSet *mutableBoxes = [self .checkBoxes mutableCopy ];
68
- [mutableBoxes removeObject: checkBox];
69
- self.checkBoxes = [NSOrderedSet orderedSetWithOrderedSet: mutableBoxes];
66
+ [self .checkBoxes removeObject: checkBox];
70
67
}
71
68
72
69
#pragma mark Getters
@@ -97,7 +94,7 @@ - (void)setSelectedCheckBox:(BEMCheckBox *)selectedCheckBox {
97
94
// Selection is nil
98
95
if (self.mustHaveSelection && [self .checkBoxes count ] > 0 ){
99
96
// We must have a selected checkbox, so re-call this method with the first checkbox
100
- self.selectedCheckBox = [self .checkBoxes firstObject ];
97
+ self.selectedCheckBox = [self .checkBoxes anyObject ];
101
98
} else {
102
99
for (BEMCheckBox *checkBox in self.checkBoxes ) {
103
100
BOOL shouldBeOn = NO ;
@@ -114,7 +111,7 @@ - (void)setMustHaveSelection:(BOOL)mustHaveSelection {
114
111
115
112
// If it must have a selection and we currently don't, select the first box
116
113
if (mustHaveSelection && !self.selectedCheckBox ) {
117
- self.selectedCheckBox = [self .checkBoxes firstObject ];
114
+ self.selectedCheckBox = [self .checkBoxes anyObject ];
118
115
}
119
116
}
120
117
0 commit comments