Latest 1.0.3
Homepage https://github.com/yulingtianxia/BlockTracker
License MIT
Platforms ios 8.0, osx 10.8, requires ARC
Dependencies BlockHook
Authors


BlockHook

CI Status
Carthage compatible
GitHub release
Twitter Follow

BlockTracker can track block arguments of a method. It’s based on BlockHook.

📚 Article

追踪 Objective-C 方法中的 Block 参数对象

🌟 Features

  • [x] Easy to use.
  • [x] Keep your code clear.
  • [x] Reserve the whole arguments.
  • [x] Get return value.
  • [x] Get invoke count.
  • [x] Trace all block args of method.
  • [x] Self-managed trackers.
  • [x] Support Carthage.

🔮 Example

The sample project "BlockTrackerSample" just only support iOS platform.

🐒 How to use

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

📲 Installation

Carthage

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.

Manual

After importing libffi, just add the two files BlockTracker.h/m to your project.

❤️ Contributed

  • 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.

👨🏻‍💻 Author

yulingtianxia, [email protected]

👮🏻 License

BlockTracker is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "BlockTracker",
    "version": "1.0.3",
    "summary": "Tracking block args of Objective-C method based on BlockHook",
    "description": "BlockTracker can track block arguments of a method. It's based on BlockHook.",
    "homepage": "https://github.com/yulingtianxia/BlockTracker",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "yulingtianxia": "[email protected]"
    },
    "social_media_url": "https://twitter.com/yulingtianxia",
    "source": {
        "git": "https://github.com/yulingtianxia/BlockTracker.git",
        "tag": "1.0.3"
    },
    "source_files": "BlockTracker/*.{h,m}",
    "public_header_files": "BlockTracker/*.h",
    "platforms": {
        "ios": "8.0",
        "osx": "10.8"
    },
    "requires_arc": true,
    "dependencies": {
        "BlockHook": []
    }
}

Pin It on Pinterest

Share This