版本記錄
版本號(hào) | 時(shí)間 |
---|---|
V1.0 | 2018.04.06 |
前言
iOS圈內(nèi)有幾個(gè)人大家基本都知道昂秃,比如說(shuō)王巍、唐巧浓冒,還有YYKit框架的作者現(xiàn)任職于滴滴的郭曜源 - ibireme等粤攒。這里有一篇唐巧對(duì)他的專訪所森,還有他的 GitHub - Yaoyuan 和 博客,這里貼出來(lái)框架YYKit 框架夯接。接下來(lái)幾篇我們就一起來(lái)看一下這個(gè)框架焕济。感興趣的可以看上面寫的幾篇。
1. YYKit源碼探究(一) —— 基本概覽
2. YYKit源碼探究(二) —— NSString分類之Hash(一)
3. YYKit源碼探究(三) —— NSString分類之Encode and decode(二)
4. YYKit源碼探究(四) —— NSString分類之Drawing(三)
5. YYKit源碼探究(五) —— NSString分類之Regular Expression(四)
6. YYKit源碼探究(六) —— NSString分類之NSNumber Compatible(五)
7. YYKit源碼探究(七) —— NSString分類之Utilities(六)
8. YYKit源碼探究(八) —— NSNumber分類(一)
9. YYKit源碼探究(九) —— UIFont分類之架構(gòu)分析和Font Traits(一)
10. YYKit源碼探究(十) —— UIFont分類之Create font(二)
11. YYKit源碼探究(十一) —— UIFont分類之Load and unload font(三)
12. YYKit源碼探究(十二) —— UIFont分類之Dump font data(四)
13. YYKit源碼探究(十三) —— UIImage分類之框架結(jié)構(gòu)和Create image部分(一)
14. YYKit源碼探究(十四) —— UIImage分類之Image Info(二)
15. YYKit源碼探究(十五) —— UIImage分類之Modify Image(三)
16. YYKit源碼探究(十六) —— UIImage分類之Image Effect(四)
17. YYKit源碼探究(十七) —— UIImageView分類之架構(gòu)和image部分(一)
18. YYKit源碼探究(十八) —— UIImageView分類之highlight image部分(二)
19. YYKit源碼探究(十九) —— UIScreen分類(一)
20. YYKit源碼探究(二十) —— UIScrollView分類(一)
21. YYKit源碼探究(二十一) —— UITableView分類(一)
22. YYKit源碼探究(二十二) —— UITextField分類(一)
23. YYKit源碼探究(二十三) —— UIView分類(一)
24. YYKit源碼探究(二十四) —— UIPasteboard分類(一)
25. YYKit源碼探究(二十五) —— UIGestureRecognizer分類(一)
26. YYKit源碼探究(二十六) —— UIDevice分類框架及Device Information(一)
27. YYKit源碼探究(二十七) —— UIDevice分類之Network Information(二)
28. YYKit源碼探究(二十八) —— UIDevice分類之Disk Space(三)
29. YYKit源碼探究(二十九) —— UIDevice分類之Memory Information(四)
30. YYKit源碼探究(三十) —— UIDevice分類之CPU Information(五)
31. YYKit源碼探究(三十一) —— UIControl分類(一)
32. YYKit源碼探究(三十二) —— UIColor分類之Create a UIColor Object(一)
33. YYKit源碼探究(三十三) —— UIColor分類之Get color's description(二)
34. YYKit源碼探究(三十四) —— UIColor分類之Retrieving Color Information(三)
35. YYKit源碼探究(三十五) —— UIButton分類之image(一)
36. YYKit源碼探究(三十六) —— UIButton分類之background image(二)
37. YYKit源碼探究(三十七) —— UIBezierPath分類(一)
38. YYKit源碼探究(三十八) —— UIBarButtonItem分類(一)
39. YYKit源碼探究(三十九) —— UIApplication分類(一)
40. YYKit源碼探究(四十) —— NSTimer分類(一)
41. YYKit源碼探究(四十一) —— NSParagraphStyle分類(一)
42. YYKit源碼探究(四十二) —— NSObject分類之YYModel(一)
43. YYKit源碼探究(四十三) —— NSObject分類之KVO(二)
44. YYKit源碼探究(四十四) —— NSObject分類之Sending messages with variable parameters(三)
45. YYKit源碼探究(四十五) —— NSObject分類之Swap method (Swizzling)(四)
46. YYKit源碼探究(四十六) —— NSObject分類之Associate value(五)
47. YYKit源碼探究(四十七) —— NSObject分類之Other(六)
48. YYKit源碼探究(四十八) —— NSNotificationCenter分類(一)
49. YYKit源碼探究(四十九) —— NSKeyedUnarchiver分類(一)
50. YYKit源碼探究(五十) —— NSDictionary分類之Dictionary Convertor(一)
51. YYKit源碼探究(五十一) —— NSDictionary分類之Dictionary Value Getter(二)
52. YYKit源碼探究(五十二) —— NSDictionary分類之NSMutableDictionary(三)
53. YYKit源碼探究(五十三) —— NSDate分類之Component Properties(一)
54. YYKit源碼探究(五十四) —— NSDate分類之Date modify(二)
55. YYKit源碼探究(五十五) —— NSDate分類之Date Format(三)
56. YYKit源碼探究(五十六) —— NSData分類之Hash(一)
57. YYKit源碼探究(五十七) —— NSData分類之Encrypt and Decrypt(二)
58. YYKit源碼探究(五十八) —— NSData分類之Encode and decode(三)
59. YYKit源碼探究(五十九) —— NSData分類之Inflate and deflate(四)
60. YYKit源碼探究(六十) —— NSData分類之Others(五)
61. YYKit源碼探究(六十一) —— NSBundle分類(一)
62. YYKit源碼探究(六十二) —— NSAttributedString分類之基本(一)
63. YYKit源碼探究(六十三) —— NSAttributedString分類之Retrieving character attribute information(二)
64. YYKit源碼探究(六十四) —— NSAttributedString分類之Get character attribute as property(三)
65. YYKit源碼探究(六十五) —— NSAttributedString分類之Get paragraph attribute as property(四)
66. YYKit源碼探究(六十六) —— NSAttributedString分類之Get YYText attribute as property(五)
67. YYKit源碼探究(六十七) —— NSAttributedString分類之Query for YYText(六)
68. YYKit源碼探究(六十八) —— NSAttributedString分類之Create attachment string for YYText(七)
69. YYKit源碼探究(六十九) —— NSAttributedString分類之Utility(八)
70. YYKit源碼探究(七十) —— NSMutableAttributedString分類之Set character attribute(九)
71. YYKit源碼探究(七十一) —— NSMutableAttributedString分類之Set character attribute as property(十)
72. YYKit源碼探究(七十二) —— NSMutableAttributedString分類之Set paragraph attribute as property(十一)
73. YYKit源碼探究(七十三) —— NSMutableAttributedString分類之Set YYText attribute as property(十二)
74. YYKit源碼探究(七十四) —— NSMutableAttributedString分類之Set discontinuous attribute for range(十三)
75. YYKit源碼探究(七十五) —— NSMutableAttributedString分類之Convenience methods for text highlight(十四)
76. YYKit源碼探究(七十六) —— NSMutableAttributedString分類之Utilities(十五)
77. YYKit源碼探究(七十七) —— NSArray分類(一)
78. YYKit源碼探究(七十八) —— NSMutableArray分類(一)
79. YYKit源碼探究(七十九) —— MKAnnotationView分類(一)
80. YYKit源碼探究(八十) —— CALayer分類之YYWebImage(一)
81. YYKit源碼探究(八十一) —— CALayer分類之YYAdd(二)
82. YYKit源碼探究(八十二) —— 網(wǎng)絡(luò)相關(guān)YYReachability(一)
83. YYKit源碼探究(八十三) —— 線程安全計(jì)數(shù)器YYSentinel(一)
回顧
上一篇主要介紹了線程安全計(jì)數(shù)器YYSentinel
部分盔几,這一篇主要看一下線程安全的可變數(shù)組子類YYThreadSafeArray
部分晴弃。
API
下面我們就看一下API文檔。
/**
A simple implementation of thread safe mutable array.
@discussion Generally, access performance is lower than NSMutableArray,
but higher than using @synchronized, NSLock, or pthread_mutex_t.
@discussion It's also compatible with the custom methods in `NSArray(YYAdd)`
and `NSMutableArray(YYAdd)`
@warning Fast enumerate(for..in) and enumerator is not thread safe,
use enumerate using block instead. When enumerate or sort with block/callback,
do *NOT* send message to the array inside the block/callback.
*/
@interface YYThreadSafeArray : NSMutableArray
@end
這個(gè)類主要就是線程安全可變數(shù)組的簡(jiǎn)單實(shí)現(xiàn)。
通常上鞠,訪問(wèn)性能低于NSMutableArray
际邻,但高于使用@synchronized
,NSLock
或pthread_mutex_t
芍阎。
與NSArray(YYAdd)
和 NSMutableArray(YYAdd)
中的自定義方法兼容世曾。
快速枚舉enumerate(for..in)
和枚舉器不是線程安全的,使用block進(jìn)行遍歷枚舉谴咸。當(dāng)使用block/callback
進(jìn)行遍歷時(shí)轮听,不要向block/callback
內(nèi)部的數(shù)組發(fā)送消息。
方法實(shí)現(xiàn)
下面我們看一下方法實(shí)現(xiàn)岭佳。
//
// YYThreadSafeArray.m
// YYKit <https://github.com/ibireme/YYKit>
//
// Created by ibireme on 14/10/21.
// Copyright (c) 2015 ibireme.
//
// This source code is licensed under the MIT-style license found in the
// LICENSE file in the root directory of this source tree.
//
#import "YYThreadSafeArray.h"
#import "NSArray+YYAdd.h"
#define INIT(...) self = super.init; \
if (!self) return nil; \
__VA_ARGS__; \
if (!_arr) return nil; \
_lock = dispatch_semaphore_create(1); \
return self;
#define LOCK(...) dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER); \
__VA_ARGS__; \
dispatch_semaphore_signal(_lock);
@implementation YYThreadSafeArray {
NSMutableArray *_arr; //Subclass a class cluster...
dispatch_semaphore_t _lock;
}
#pragma mark - init
- (instancetype)init {
INIT(_arr = [[NSMutableArray alloc] init]);
}
- (instancetype)initWithCapacity:(NSUInteger)numItems {
INIT(_arr = [[NSMutableArray alloc] initWithCapacity:numItems]);
}
- (instancetype)initWithArray:(NSArray *)array {
INIT(_arr = [[NSMutableArray alloc] initWithArray:array]);
}
- (instancetype)initWithObjects:(const id[])objects count:(NSUInteger)cnt {
INIT(_arr = [[NSMutableArray alloc] initWithObjects:objects count:cnt]);
}
- (instancetype)initWithContentsOfFile:(NSString *)path {
INIT(_arr = [[NSMutableArray alloc] initWithContentsOfFile:path]);
}
- (instancetype)initWithContentsOfURL:(NSURL *)url {
INIT(_arr = [[NSMutableArray alloc] initWithContentsOfURL:url]);
}
#pragma mark - method
- (NSUInteger)count {
LOCK(NSUInteger count = _arr.count); return count;
}
- (id)objectAtIndex:(NSUInteger)index {
LOCK(id obj = [_arr objectAtIndex:index]); return obj;
}
- (NSArray *)arrayByAddingObject:(id)anObject {
LOCK(NSArray * arr = [_arr arrayByAddingObject:anObject]); return arr;
}
- (NSArray *)arrayByAddingObjectsFromArray:(NSArray *)otherArray {
LOCK(NSArray * arr = [_arr arrayByAddingObjectsFromArray:otherArray]); return arr;
}
- (NSString *)componentsJoinedByString:(NSString *)separator {
LOCK(NSString * str = [_arr componentsJoinedByString:separator]); return str;
}
- (BOOL)containsObject:(id)anObject {
LOCK(BOOL c = [_arr containsObject:anObject]); return c;
}
- (NSString *)description {
LOCK(NSString * d = _arr.description); return d;
}
- (NSString *)descriptionWithLocale:(id)locale {
LOCK(NSString * d = [_arr descriptionWithLocale:locale]); return d;
}
- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level {
LOCK(NSString * d = [_arr descriptionWithLocale:locale indent:level]); return d;
}
- (id)firstObjectCommonWithArray:(NSArray *)otherArray {
LOCK(id o = [_arr firstObjectCommonWithArray:otherArray]); return o;
}
- (void)getObjects:(id __unsafe_unretained[])objects range:(NSRange)range {
LOCK([_arr getObjects:objects range:range]);
}
- (NSUInteger)indexOfObject:(id)anObject {
LOCK(NSUInteger i = [_arr indexOfObject:anObject]); return i;
}
- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range {
LOCK(NSUInteger i = [_arr indexOfObject:anObject inRange:range]); return i;
}
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject {
LOCK(NSUInteger i = [_arr indexOfObjectIdenticalTo:anObject]); return i;
}
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(NSRange)range {
LOCK(NSUInteger i = [_arr indexOfObjectIdenticalTo:anObject inRange:range]); return i;
}
- (id)firstObject {
LOCK(id o = _arr.firstObject); return o;
}
- (id)lastObject {
LOCK(id o = _arr.lastObject); return o;
}
- (NSEnumerator *)objectEnumerator {
LOCK(NSEnumerator * e = [_arr objectEnumerator]); return e;
}
- (NSEnumerator *)reverseObjectEnumerator {
LOCK(NSEnumerator * e = [_arr reverseObjectEnumerator]); return e;
}
- (NSData *)sortedArrayHint {
LOCK(NSData * d = [_arr sortedArrayHint]); return d;
}
- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context {
LOCK(NSArray * arr = [_arr sortedArrayUsingFunction:comparator context:context]) return arr;
}
- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context hint:(NSData *)hint {
LOCK(NSArray * arr = [_arr sortedArrayUsingFunction:comparator context:context hint:hint]); return arr;
}
- (NSArray *)sortedArrayUsingSelector:(SEL)comparator {
LOCK(NSArray * arr = [_arr sortedArrayUsingSelector:comparator]); return arr;
}
- (NSArray *)subarrayWithRange:(NSRange)range {
LOCK(NSArray * arr = [_arr subarrayWithRange:range]) return arr;
}
- (void)makeObjectsPerformSelector:(SEL)aSelector {
LOCK([_arr makeObjectsPerformSelector:aSelector]);
}
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument {
LOCK([_arr makeObjectsPerformSelector:aSelector withObject:argument]);
}
- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes {
LOCK(NSArray * arr = [_arr objectsAtIndexes:indexes]); return arr;
}
- (id)objectAtIndexedSubscript:(NSUInteger)idx {
LOCK(id o = [_arr objectAtIndexedSubscript:idx]); return o;
}
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
LOCK([_arr enumerateObjectsUsingBlock:block]);
}
- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
LOCK([_arr enumerateObjectsWithOptions:opts usingBlock:block]);
}
- (void)enumerateObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
LOCK([_arr enumerateObjectsAtIndexes:s options:opts usingBlock:block]);
}
- (NSUInteger)indexOfObjectPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate {
LOCK(NSUInteger i = [_arr indexOfObjectPassingTest:predicate]); return i;
}
- (NSUInteger)indexOfObjectWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate {
LOCK(NSUInteger i = [_arr indexOfObjectWithOptions:opts passingTest:predicate]); return i;
}
- (NSUInteger)indexOfObjectAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate {
LOCK(NSUInteger i = [_arr indexOfObjectAtIndexes:s options:opts passingTest:predicate]); return i;
}
- (NSIndexSet *)indexesOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate {
LOCK(NSIndexSet * i = [_arr indexesOfObjectsPassingTest:predicate]); return i;
}
- (NSIndexSet *)indexesOfObjectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate {
LOCK(NSIndexSet * i = [_arr indexesOfObjectsWithOptions:opts passingTest:predicate]); return i;
}
- (NSIndexSet *)indexesOfObjectsAtIndexes:(NSIndexSet *)s options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate {
LOCK(NSIndexSet * i = [_arr indexesOfObjectsAtIndexes:s options:opts passingTest:predicate]); return i;
}
- (NSArray *)sortedArrayUsingComparator:(NSComparator)cmptr {
LOCK(NSArray * a = [_arr sortedArrayUsingComparator:cmptr]); return a;
}
- (NSArray *)sortedArrayWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr {
LOCK(NSArray * a = [_arr sortedArrayWithOptions:opts usingComparator:cmptr]); return a;
}
- (NSUInteger)indexOfObject:(id)obj inSortedRange:(NSRange)r options:(NSBinarySearchingOptions)opts usingComparator:(NSComparator)cmp {
LOCK(NSUInteger i = [_arr indexOfObject:obj inSortedRange:r options:opts usingComparator:cmp]); return i;
}
#pragma mark - mutable
- (void)addObject:(id)anObject {
LOCK([_arr addObject:anObject]);
}
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index {
LOCK([_arr insertObject:anObject atIndex:index]);
}
- (void)removeLastObject {
LOCK([_arr removeLastObject]);
}
- (void)removeObjectAtIndex:(NSUInteger)index {
LOCK([_arr removeObjectAtIndex:index]);
}
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject {
LOCK([_arr replaceObjectAtIndex:index withObject:anObject]);
}
- (void)addObjectsFromArray:(NSArray *)otherArray {
LOCK([_arr addObjectsFromArray:otherArray]);
}
- (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2 {
LOCK([_arr exchangeObjectAtIndex:idx1 withObjectAtIndex:idx2]);
}
- (void)removeAllObjects {
LOCK([_arr removeAllObjects]);
}
- (void)removeObject:(id)anObject inRange:(NSRange)range {
LOCK([_arr removeObject:anObject inRange:range]);
}
- (void)removeObject:(id)anObject {
LOCK([_arr removeObject:anObject]);
}
- (void)removeObjectIdenticalTo:(id)anObject inRange:(NSRange)range {
LOCK([_arr removeObjectIdenticalTo:anObject inRange:range]);
}
- (void)removeObjectIdenticalTo:(id)anObject {
LOCK([_arr removeObjectIdenticalTo:anObject]);
}
- (void)removeObjectsInArray:(NSArray *)otherArray {
LOCK([_arr removeObjectsInArray:otherArray]);
}
- (void)removeObjectsInRange:(NSRange)range {
LOCK([_arr removeObjectsInRange:range]);
}
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange {
LOCK([_arr replaceObjectsInRange:range withObjectsFromArray:otherArray range:otherRange]);
}
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray {
LOCK([_arr replaceObjectsInRange:range withObjectsFromArray:otherArray]);
}
- (void)setArray:(NSArray *)otherArray {
LOCK([_arr setArray:otherArray]);
}
- (void)sortUsingFunction:(NSInteger (*)(id, id, void *))compare context:(void *)context {
LOCK([_arr sortUsingFunction:compare context:context]);
}
- (void)sortUsingSelector:(SEL)comparator {
LOCK([_arr sortUsingSelector:comparator]);
}
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes {
LOCK([_arr insertObjects:objects atIndexes:indexes]);
}
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes {
LOCK([_arr removeObjectsAtIndexes:indexes]);
}
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects {
LOCK([_arr replaceObjectsAtIndexes:indexes withObjects:objects]);
}
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx {
LOCK([_arr setObject:obj atIndexedSubscript:idx]);
}
- (void)sortUsingComparator:(NSComparator)cmptr {
LOCK([_arr sortUsingComparator:cmptr]);
}
- (void)sortWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr {
LOCK([_arr sortWithOptions:opts usingComparator:cmptr]);
}
- (BOOL)isEqualToArray:(NSArray *)otherArray {
if (otherArray == self) return YES;
if ([otherArray isKindOfClass:YYThreadSafeArray.class]) {
YYThreadSafeArray *other = (id)otherArray;
BOOL isEqual;
dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(other->_lock, DISPATCH_TIME_FOREVER);
isEqual = [_arr isEqualToArray:other->_arr];
dispatch_semaphore_signal(other->_lock);
dispatch_semaphore_signal(_lock);
return isEqual;
}
return NO;
}
#pragma mark - protocol
- (id)copyWithZone:(NSZone *)zone {
return [self mutableCopyWithZone:zone];
}
- (id)mutableCopyWithZone:(NSZone *)zone {
LOCK(id copiedDictionary = [[self.class allocWithZone:zone] initWithArray:_arr]);
return copiedDictionary;
}
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
objects:(id __unsafe_unretained[])stackbuf
count:(NSUInteger)len {
LOCK(NSUInteger count = [_arr countByEnumeratingWithState:state objects:stackbuf count:len]);
return count;
}
- (BOOL)isEqual:(id)object {
if (object == self) return YES;
if ([object isKindOfClass:YYThreadSafeArray.class]) {
YYThreadSafeArray *other = object;
BOOL isEqual;
dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER);
dispatch_semaphore_wait(other->_lock, DISPATCH_TIME_FOREVER);
isEqual = [_arr isEqual:other->_arr];
dispatch_semaphore_signal(other->_lock);
dispatch_semaphore_signal(_lock);
return isEqual;
}
return NO;
}
- (NSUInteger)hash {
LOCK(NSUInteger hash = [_arr hash]);
return hash;
}
#pragma mark - custom methods for NSArray(YYAdd)
- (id)randomObject {
LOCK(id o = [_arr randomObject]) return o;
}
- (id)objectOrNilAtIndex:(NSUInteger)index {
LOCK(id o = [_arr objectOrNilAtIndex:index]) return o;
}
- (void)removeFirstObject {
LOCK([_arr removeFirstObject]);
}
- (id)popFirstObject {
LOCK(id o = [_arr popFirstObject]) return o;
}
- (id)popLastObject {
LOCK(id o = [_arr popLastObject]) return o;
}
- (void)appendObjects:(NSArray *)objects {
LOCK([_arr appendObjects:objects]);
}
- (void)prependObjects:(NSArray *)objects {
LOCK([_arr prependObjects:objects]);
}
- (void)insertObjects:(NSArray *)objects atIndex:(NSUInteger)index {
LOCK([_arr insertObjects:objects atIndex:index]);
}
- (void)reverse {
LOCK([_arr reverse]);
}
- (void)shuffle {
LOCK([_arr shuffle]);
}
@end
后記
本篇主要介紹了線程安全的可變數(shù)組子類
YYThreadSafeArray
血巍,感興趣的給個(gè)贊或者關(guān)注~~~