Skip to content

TangentW/MessageListener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MessageListener

A tool for monitoring objc message called.

Carthage compatible CocoaPods

Guide & Blog

Tangentw - 基于isa-swizzling实现消息监听,扩展响应式框架

Installation

Carthage

Add MessageListener in your Cartfile:

github "TangentW/MessageListener"

Run carthage update to build the framework and drag into your project.

Cocoapods

Add MessageListener in your Podfile:

use_frameworks!

pod "MessageListener"

Run the following command:

$ pod install

Manually

  1. Download the source code.
  2. Drag files NSObject+Listener.h and NSObject+Listener.m into your project.

Usage

Use method listen.

For normal method

Objc

[self listen: @selector(touchesBegan:withEvent:) with:^(NSArray * _Nonnull parameters) {
	NSLog(@"Touches began");
}];

Swift

listen(#selector(ViewController.touchesBegan(_:with:))) { _ in
	print("Touches began")
}

For protocol method

Objc

[self listen: @selector(tableView:didSelectRowAtIndexPath:) in:@protocol(UITableViewDelegate) with:^(NSArray * _Nonnull parameters) {
	if (parameters.count != 2) return;
	NSIndexPath *indexPath = parameters[1];
	NSLog(@"Did selected row %ld", (long)indexPath.row);
}];

Swift

listen(#selector(UITableViewDelegate.scrollViewDidScroll(_:)), in: UITableViewDelegate.self).subscribe(next: { parameters in
	guard let tableView = parameters.first as? UITableView else { return }
		print(tableView.contentOffset.y)
})
_tableView.delegate = self

License

The MIT License (MIT)

About

A tool for monitoring message called

Resources

License

Stars

Watchers

Forks

Packages

No packages published