TTGDeallocTaskHelper 可以在对象析构后执行任务。
TTGDeallocTaskHelper 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod "TTGDeallocTaskHelper"
#import "NSObject+TTGDeallocTaskHelper.h"
// Some object
id object;
// Add dealloc task
[object ttg_addDeallocTask:^(__unsafe_unretained id object, NSUInteger identifier) {
// After object dealloc, do you job.
// ...
}];
// object has been released. And the tasks will be performed.
object = nil;
回调块定义。
typedef void (^TTGDeallocTaskBlock)(__unsafe_unretained id object, NSUInteger identifier);
添加析构任务。
/**
* Add dealloc task to object.
*
* @param taskBlock The dealloc task
*
* @return The task identifier
*/
- (NSUInteger)ttg_addDeallocTask:(TTGDeallocTaskBlock)taskBlock;
通过标识符移除特定任务。
/**
* Remove task by identifier.
*
* @param identifier The task identifier
*
* @return Remove success or not
*/
- (BOOL)ttg_removeDeallocTaskByIdentifier:(NSUInteger)identifier;
移除所有析构任务。
/**
* Remove all dealloc tasks.
*/
- (void)ttg_removeAllDeallocTasks;
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
zekunyan, [email protected]
TTGDeallocTaskHelper 根据 MIT 许可证提供。查看 LICENSE 文件以获取更多信息。