{"id":15500926,"url":"https://github.com/yulingtianxia/blocktracker","last_synced_at":"2025-08-24T00:07:02.142Z","repository":{"id":56903799,"uuid":"126943407","full_name":"yulingtianxia/BlockTracker","owner":"yulingtianxia","description":"Tracking block args of Objective-C method based on BlockHook","archived":false,"fork":false,"pushed_at":"2022-01-16T12:42:04.000Z","size":756,"stargazers_count":78,"open_issues_count":1,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-10T15:24:33.597Z","etag":null,"topics":["blockhook","blocktracker","carthage","cocoapods","hookblock"],"latest_commit_sha":null,"homepage":"http://yulingtianxia.com/blog/2018/03/31/Track-Block-Arguments-of-Objective-C-Method/","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yulingtianxia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-27T07:04:08.000Z","updated_at":"2024-02-14T23:59:00.000Z","dependencies_parsed_at":"2022-08-21T02:50:16.183Z","dependency_job_id":null,"html_url":"https://github.com/yulingtianxia/BlockTracker","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yulingtianxia%2FBlockTracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yulingtianxia%2FBlockTracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yulingtianxia%2FBlockTracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yulingtianxia%2FBlockTracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yulingtianxia","download_url":"https://codeload.github.com/yulingtianxia/BlockTracker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250330421,"owners_count":21412979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockhook","blocktracker","carthage","cocoapods","hookblock"],"created_at":"2024-10-02T09:01:38.906Z","updated_at":"2025-04-22T21:44:14.138Z","avatar_url":"https://github.com/yulingtianxia.png","language":"Objective-C","readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/yulingtianxia/BlockTracker\"\u003e\n\u003cimg src=\"Assets/logo.png\" alt=\"BlockTracker\" /\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n[![CI Status](http://img.shields.io/travis/yulingtianxia/BlockTracker.svg?style=flat)](https://travis-ci.org/yulingtianxia/BlockTracker)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![GitHub release](https://img.shields.io/github/release/yulingtianxia/blocktracker.svg)](https://github.com/yulingtianxia/BlockTracker/releases)\n[![Twitter Follow](https://img.shields.io/twitter/follow/yulingtianxia.svg?style=social\u0026label=Follow)](https://twitter.com/yulingtianxia)\n\n# BlockTracker\n\nBlockTracker can track block arguments of a method. It's based on [BlockHook](https://github.com/yulingtianxia/BlockHook).\n\n## 📚 Article\n\n[追踪 Objective-C 方法中的 Block 参数对象](http://yulingtianxia.com/blog/2018/03/31/Track-Block-Arguments-of-Objective-C-Method/)\n\n## 🌟 Features\n\n- [x] Easy to use.\n- [x] Keep your code clear.\n- [x] Let you modify return value and arguments.\n- [x] Trace all block args of method.\n- [x] Trace all `NSMallocBlock`.\n- [x] Self-managed trackers.\n- [x] Support CocoaPods \u0026 Carthage.\n\n## 🔮 Example\n\nThe sample project \"BlockTrackerSample\" just only support iOS platform.\n\n## 🐒 How to use\n\n### Track blocks in method\nYou 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.\n\n```objc\n__unused BTTracker *tracker = [self bt_trackBlockArgOfSelector:@selector(performBlock:) callback:^(BHInvocation * _Nonnull invocation) {\n    switch (invocation.mode) {\n        case BlockHookModeBefore:\n            NSLog(@\"Before block:%@, mangleName:%@\", invocation.token.block, invocation.token.mangleName);\n            break;\n        case BlockHookModeAfter:\n            NSLog(@\"After block:%@, mangleName:%@\", invocation.token.block, invocation.token.mangleName);\n            objc_setAssociatedObject(invocation.token, @\"invoked\", @YES, OBJC_ASSOCIATION_RETAIN);\n            break;\n        case BlockHookModeDead:\n            NSLog(@\"Block Dead! mangleName:%@\", invocation.token.mangleName);\n            BOOL invoked = [objc_getAssociatedObject(invocation.token, @\"invoked\") boolValue];\n            if (!invoked) {\n                NSLog(@\"Block Not Invoked Before Dead! %@\", invocation.token.mangleName);\n            }\n            break;\n        default:\n            break;\n    }\n}];\n    \n// invoke blocks\nNSString *word = @\"I'm a block\";\n[self performBlock:^{\n    NSLog(@\"%@\", word);\n}];\n// stop tracker in future\n//    [tracker stop];\n// blocks will die\n\n- (void)performBlock:(void(^)(void))block {\n    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), block);\n}\n\n@end\n```\n\nHere is the log:\n\n```\nHook Block Arg mangleName:__42-[BlockTrackerSampleTests testTrackMethod]_block_invoke_2, in selector:performBlock:\nBefore block:\u003c__NSMallocBlock__: 0x600000c71aa0\u003e, mangleName:__42-[BlockTrackerSampleTests testTrackMethod]_block_invoke_2\nI'm a block\nAfter block:\u003c__NSMallocBlock__: 0x600000c71aa0\u003e, mangleName:__42-[BlockTrackerSampleTests testTrackMethod]_block_invoke_2\nBlock Dead! mangleName:__42-[BlockTrackerSampleTests testTrackMethod]_block_invoke_2\r\n```\n\n### Track a batch of blocks.\n\n```objc\nsetMallocBlockCallback(^(BHInvocation * _Nonnull invocation) {\n    switch (invocation.mode) {\n        case BlockHookModeBefore: {\n            NSLog(@\"Before block:%@, mangleName:%@\", invocation.token.block, invocation.token.mangleName);\n            break;\n        }\n        case BlockHookModeAfter: {\n            NSLog(@\"After block:%@, mangleName:%@\", invocation.token.block, invocation.token.mangleName);\n            objc_setAssociatedObject(invocation.token, @\"invoked\", @YES, OBJC_ASSOCIATION_RETAIN);\n            break;\n        }\n        case BlockHookModeDead: {\n            NSLog(@\"Block Dead! mangleName:%@\", invocation.token.mangleName);\n            BOOL invoked = [objc_getAssociatedObject(invocation.token, @\"invoked\") boolValue];\n            if (!invoked) {\n                NSLog(@\"Block Not Invoked Before Dead! %@\", invocation.token.mangleName);\n            }\n            break;\n        }\n        default:\n            break;\n    }\n});\n```\n\n## 📲 Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate BlockTracker into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n\n```\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\ntarget 'MyApp' do\n\tpod 'BlockTracker'\nend\n```\n\nYou need replace \"MyApp\" with your project's name.\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate BlockTracker into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"yulingtianxia/BlockTracker\"\n```\n\nRun `carthage update` to build the framework and drag the built `BlockTrackerKit.framework` into your Xcode project.\n\n### Manual\n\nJust drag source files in `BlockTracker` folder to your project.\n\n## ❤️ Contributed\n\n- If you **need help** or you'd like to **ask a general question**, open an issue.\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n## 👨🏻‍💻 Author\n\nyulingtianxia, yulingtianxia@gmail.com\n\n## 👮🏻 License\n\nBlockTracker is available under the MIT license. See the LICENSE file for more info.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyulingtianxia%2Fblocktracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyulingtianxia%2Fblocktracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyulingtianxia%2Fblocktracker/lists"}