HMCThreadSafeMutableCollection 0.1.0

HMCThreadSafeMutableCollection 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2017

Maintained by Chuong Huynh.



  • By
  • Chuong M. Huynh



NSMutableArray, NSMutableDictionary is threadunsafe (race condition would appear when a NSMutableArray, NSMutableDictionary accessed from multiple threads). This project is a threadsafe wrapper, which provides base methods for creating, adding, removing and accessing object in an array without race condition.

Usage

HMCThreadSafeMutableArray

1. Create an empty instance

HMCThreadSafeMutableArray *array = [[HMCThreadSafeMutableArray alloc] init];

2. Create from a NSArray

NSArray *array = @[@1,@2,@3];
HMCThreadSafeMutableArray *tsarray = [[HMCThreadSafeMutableArray alloc] initWithArray:array];

3. Add one object to the end of array

- (void)addObject:(NSObject *)object;

4. Add multiple objects from NSArray

- (void)addObjectsFromArray:(NSArray *)array;

5. Insert an object with index to array

- (void)insertObject:(NSObject *)object
             atIndex:(NSUInteger)index;

6. Remove an object from array

- (void)removeObject:(NSObject *)object;

7. Remove object at index from array

- (void)removeObjectAtIndex:(NSUInteger)index;

8. Remove all objects

- (void)removeAllObjects;

9. Get object at index in array

- (id)objectAtIndex:(NSUInteger)index;

10. Get number of elements in array

- (NSUInteger)count;

11. Filter array using prdicate

- (NSArray *)filteredArrayUsingPredicate: (NSPredicate *) predicate;

12. Get index of object

- (NSInteger)indexOfObject: (NSObject *)object;

13. Check whether array contains object

- (BOOL)containsObject: (id)object;

14. Convert to NSArray contains all elements

- (NSArray *)toNSArray;

HMCThreadSafeMutableDictionary

1. Create an empty instance

HMCThreadSafeMutableDictionary *dict = [[HMCThreadSafeMutableDictionary alloc] init];

2. Get, add or change object using subscript

dict[@"a"] = @1;
id object = dict[@"a"];

3. Remove all objects

- (void)removeAllObjects;

4. Remove object for key

- (void)removeObjectForkey:(NSString *)key;

5. Convert to NSDictionray

- (NSDictionary *)toNSDictionary;

Author

chuonghuynh, [email protected]

License

HMCThreadSafeMutableCollection is available under the MIT license. See the LICENSE file for more info.