Latest 0.1.0
Homepage https://github.com/hmchuong/iOS-ObjectiveC-HMCThreadSafeMutableCollection
License MIT
Platforms osx , ios , tvos , watchos
Authors

Version
License
Platform

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.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate HMCThreadSafeMutableCollection into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'HMCThreadSafeMutableCollection'
end

Then, run the following command:

$ pod install

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.

Latest podspec

{
    "name": "HMCThreadSafeMutableCollection",
    "version": "0.1.0",
    "summary": "Thread Safe Mutable Collection",
    "description": "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.",
    "homepage": "https://github.com/hmchuong/iOS-ObjectiveC-HMCThreadSafeMutableCollection",
    "license": "MIT",
    "authors": {
        "Chuong M. Huynh": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hmchuong/iOS-ObjectiveC-HMCThreadSafeMutableCollection.git",
        "tag": "0.1.0"
    },
    "source_files": "HMCThreadSafeMutableCollection/*.{h,m}",
    "exclude_files": "HMCThreadSafeMutableCollection/Exclude",
    "platforms": {
        "osx": null,
        "ios": null,
        "tvos": null,
        "watchos": null
    }
}

Pin It on Pinterest

Share This