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

iOS-ObjectiveC-HMCThreadSafeMutableCollection

cocoapods 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;

Latest podspec

{
    "name": "HMCThreadSafeMutableArray",
    "version": "0.0.1",
    "summary": "HMCThreadSafeMutableArray is an array that can be use safely in mutiple threads, handling with race condition",
    "description": "NSMutableArray is threadunsafe (race condition would appear when a NSMutableArray 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-HMCThreadSafeMultipleArray",
    "license": "MIT",
    "authors": {
        "Chuong M. Huynh": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hmchuong/iOS-ObjectiveC-HMCThreadSafeMultipleArray.git",
        "tag": "0.0.1"
    },
    "source_files": [
        "HMCThreadSafeMutableArray",
        "HMCThreadSafeMutableArray/**/*.{h,m}"
    ],
    "exclude_files": "HMCThreadSafeMutableArray/Exclude",
    "platforms": {
        "osx": null,
        "ios": null,
        "tvos": null,
        "watchos": null
    },
    "deprecated": true
}

Pin It on Pinterest

Share This