1111
1212@interface BEMCheckBoxGroup ()
1313
14- @property (nonatomic , strong , nonnull ) NSOrderedSet <BEMCheckBox *> *checkBoxes;
14+ @property (nonatomic , strong , nonnull ) NSHashTable *checkBoxes;
1515
1616@end
1717
1818/* * Defines private methods that we can call on the check box.
1919 */
2020@interface BEMCheckBox ()
2121
22- @property (weak , nonatomic , nullable ) BEMCheckBoxGroup *group;
22+ @property (strong , nonatomic , nullable ) BEMCheckBoxGroup *group;
2323
2424- (void )_setOn : (BOOL )on animated : (BOOL )animated notifyGroup : (BOOL )notifyGroup ;
2525
@@ -31,7 +31,7 @@ - (instancetype)init {
3131 self = [super init ];
3232 if (self) {
3333 _mustHaveSelection = NO ;
34- _checkBoxes = [NSOrderedSet orderedSet ];
34+ _checkBoxes = [NSHashTable hashTableWithOptions: NSPointerFunctionsWeakMemory ];
3535 }
3636 return self;
3737}
@@ -52,9 +52,8 @@ - (void)addCheckBoxToGroup:(nonnull BEMCheckBox *)checkBox {
5252
5353 [checkBox _setOn: NO animated: NO notifyGroup: NO ];
5454 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];
5857}
5958
6059- (void )removeCheckBoxFromGroup : (nonnull BEMCheckBox *)checkBox {
@@ -64,9 +63,7 @@ - (void)removeCheckBoxFromGroup:(nonnull BEMCheckBox *)checkBox {
6463 }
6564
6665 checkBox.group = nil ;
67- NSMutableOrderedSet *mutableBoxes = [self .checkBoxes mutableCopy ];
68- [mutableBoxes removeObject: checkBox];
69- self.checkBoxes = [NSOrderedSet orderedSetWithOrderedSet: mutableBoxes];
66+ [self .checkBoxes removeObject: checkBox];
7067}
7168
7269#pragma mark Getters
@@ -97,7 +94,7 @@ - (void)setSelectedCheckBox:(BEMCheckBox *)selectedCheckBox {
9794 // Selection is nil
9895 if (self.mustHaveSelection && [self .checkBoxes count ] > 0 ){
9996 // 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 ];
10198 } else {
10299 for (BEMCheckBox *checkBox in self.checkBoxes ) {
103100 BOOL shouldBeOn = NO ;
@@ -114,7 +111,7 @@ - (void)setMustHaveSelection:(BOOL)mustHaveSelection {
114111
115112 // If it must have a selection and we currently don't, select the first box
116113 if (mustHaveSelection && !self.selectedCheckBox ) {
117- self.selectedCheckBox = [self .checkBoxes firstObject ];
114+ self.selectedCheckBox = [self .checkBoxes anyObject ];
118115 }
119116}
120117
0 commit comments