APAsyncDictionary 是对 NSMutableDictionary 的包装,它在自己的 串行队列 中执行操作,并将结果返回给调用者的线程。当应用程序从不同的线程并发地使用 dictionary
时,这非常有用。
NSDictionary
设置对象和键NSArray
对象将 APAsyncDictionary
pod 添加到 Podfile
// instantiation
APAsyncDictionary *dictionary = [[APAsyncDictionary alloc] init];
...
// get object for key
__block id someObject;
[dictionary objectForKey:@"key" callback:^(id <NSCopying> key, id object)
{
someObject = object;
// do something with object
}];
...
// get object for key synchronously
someObject = [dictionary objectForKeySynchronously:@"key"];
...
// set object
[dictionary setObject:object forKey:@"key"];
...
// set objects and keys from dictionary
[dictionary setObjectsAndKeysFromDictionary:@{@"key1" : object1, @"key2" : object2}];
...
// remove object for key
[dictionary removeObjectForKey:@"key"];
...
// remove objects for keys from array
[dictionary removeObjectsForKeys:@[@"key1", @"key2"]];
...
// remove all objects
[dictionary removeAllObjects];
...
// get objects count
[dictionary objectsCountCallback:^(NSUInteger count)
{
// do something with count
}];
...
// get objects count synchronously
NSUInteger count = [dictionary objectsCountSynchronously];
...
// all keys
[dictionary allKeysCallback:^(NSArray *keys)
{
// do something with keys
}];
...
// all objects
[dictionary allObjectsCallback:^(NSArray *objects)
{
// do something with objects
}];
版本 0.0.5
版本 0.0.4
版本 0.0.3
如果您有改进或担忧,请随时在 issue 中发表并写下详细信息。