OrderedDictionary
OrderedDictionary copied to clipboard
I found that your previous version contained the sorting API, but it was wrong. I have corrected it for you. Now I can't find this api.
- (void)sortWithValuesUsingComparator:(NSComparator NS_NOESCAPE)cmptr{ //[self.readWriteLock lock]; NSArray *valuesBefore = _mutableValues.copy; NSArray *keysBefore = _mutableKeys.copy; [_mutableValues sortUsingComparator:cmptr]; [_mutableKeys sortUsingComparator:^NSComparisonResult(id _Nonnull key1, id _Nonnull key2) { ///find the obj before sort operation with key NSInteger keyIndexBefore1 = [keysBefore indexOfObject:key1]; id obj1 = valuesBefore[keyIndexBefore1]; NSInteger keyIndexBefore2 = [keysBefore indexOfObject:key2]; id obj2 = valuesBefore[keyIndexBefore2]; ///find the objct index in sorted values NSInteger index1 = [_mutableValues indexOfObject:obj1];; NSInteger index2 = [_mutableValues indexOfObject:obj2];; return index2<index1; }]; //[self.readWriteLock unlock]; }