BlockTracker can track block arguments of a method. It's based on BlockHook.
追踪 Objective-C 方法中的 Block 参数对象
- Easy to use.
- Keep your code clear.
- Reserve the whole arguments.
- Get return value.
- Get invoke count.
- Trace all block args of method.
- Self-managed trackers.
- Support Carthage.
The sample project "BlockTrackerSample" just only support iOS platform.
You can track blocks in arguments. This method returns a BTTracker
instance for more control. You can stop
a BTTracker
when you don't want to track it anymore.
- (void)viewDidLoad {
[super viewDidLoad];
// Begin Track
BTTracker *tracker = [self bt_trackBlockArgOfSelector:@selector(performBlock:) callback:^(id _Nullable block, BlockTrackerCallbackType type, NSInteger invokeCount, void * _Nullable * _Null_unspecified args, void * _Nullable result, NSArray<NSString *> * _Nonnull callStackSymbols) {
NSLog(@"%@ invoke count = %ld", BlockTrackerCallbackTypeInvoke == type ? @"BlockTrackerCallbackTypeInvoke" : @"BlockTrackerCallbackTypeDead", (long)invokeCount);
}];
// invoke blocks
__block NSString *word = @"I'm a block";
[self performBlock:^{
NSLog(@"add '!!!' to word");
word = [word stringByAppendingString:@"!!!"];
}];
[self performBlock:^{
NSLog(@"%@", word);
}];
// stop tracker in future
// [tracker stop];
// blocks will die
}
- (void)performBlock:(void(^)(void))block {
block();
// block();
}
@end
Here is the log:
add '!!!' to word
BlockTrackerCallbackTypeInvoke invoke count = 1
I'm a block!!!
BlockTrackerCallbackTypeInvoke invoke count = 1
BlockTrackerCallbackTypeDead invoke count = 1
BlockTrackerCallbackTypeDead invoke count = 1
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate BlockTracker into your Xcode project using Carthage, specify it in your Cartfile
:
github "yulingtianxia/BlockTracker"
Run carthage update
to build the framework and drag the built BlockTrackerKit.framework
into your Xcode project.
After importing libffi, just add the two files BlockTracker.h/m
to your project.
- If you need help or you'd like to ask a general question, open an issue.
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
yulingtianxia, yulingtianxia@gmail.com
BlockTracker is available under the MIT license. See the LICENSE file for more info.