SYOperationQueue
这是一个允许 LIFO 风格排队和最大操作数的操作队列子类。
我做这个是为了在滚动大 UICollectionView
时加载图像。当设置正确时,它将加载集合视图需要的图像,即使用户滚动,也会快速加载所需的第一张图像。
头文件
这个队列不是从 NSOperationQueue
继承,但应该提供足够相似的接口,以便轻松切换到两者之间。
typedef enum : NSUInteger {
SYOperationQueueModeFIFO,
SYOperationQueueModeLIFO,
} SYOperationQueueMode;
@interface SYOperationQueue : NSObject
@property (readonly, copy) NSArray <__kindof NSOperation *> *operations;
@property (readonly) NSUInteger operationCount;
@property (getter=isSuspended) BOOL suspended;
@property (copy) NSString *name;
@property (nonatomic) NSInteger maxConcurrentOperationCount;
@property (nonatomic) NSInteger maxSurvivingOperations;
@property (nonatomic) SYOperationQueueMode mode;
- (void)addOperation:(__kindof NSOperation *)op;
- (void)addOperationWithBlock:(void(^)(void))block;
- (void)cancelAllOperations;
@end