Giter Club home page Giter Club logo

yhproxyrouter's Introduction

YHProxyRouter

Travis CocoaPods CocoaPods CocoaPods Laguage CocoaPods 简书 GitHub stars

☀️一个用Object-C 写的实现多继承, 而且解耦功能强大的工具。

May you spend your life in the way you like,this sentence is so beautiful.

"愿你以自己喜欢的方式度过一生",这句话太美了。

欢迎访问我的简书:http://www.jianshu.com/u/7c43d8cb3cff

目录 Contents

环境 Requirements

  • iOS 7.0+
  • Xcode 7.0+
  • Objective-C

介绍 Introduction

☀️ 一个用Object-C 写的实现多继承, 而且解耦功能强大的工具。

  • iOS 7.0 +,Demo 需要 xcode 9.0+环境运行。

  • 通过NSProxy作为中间代理,通过消息转发的形式,实现多个类方法的统一调度,变相实现多继承。

  • 注册类和反方调用都是通过传入字符串形式,不需要导入头文件, 基本实现解耦功能。

  • 有两种调用方式, 一种是通过直接创建,第二种通过类别给NSObject添加属性,直接可用点语法创建,传入注册类。

💬 告示

欢迎大家使用,有问题请及时联系我.

直接 PR 或者发我邮箱 [email protected] 都可!

使用 Usage

  • 两种导入方法:

  • 方法一:CocoaPodspod 'YHProxyRouter'

  • 方法二:直接把 sources 文件夹(在 Demo 中)拖拽到你的项目中

  • 在相应位置导入头文件:#import "YHProxy.h"

  • 使用下列任意方法都可以:

  1. 直接创建,初始化 YHProxyRouter对象.
YHProxyRouter *proxyTool = [YHProxyRouter initWithTargets:[self getModels]];
//1.无参数 方法
[proxyTool executeMethod:@"modelOneFunction"];
//2.无参数多个方法
[proxyTool executeMethods:[self getMethods]];
//3.一个参数
[proxyTool executeMethod:@"oneParamWith:" param:@"南风不竞"];
//4.多个参数
[proxyTool executeMethod:@"modelTwoParam:bigName:" params:@[@"练峨眉",@"一页书"]];

//注:单个参数 方法名可以省略 :  多个参数方法名不可省略中间的:
//   如果两个model中  方法名字一样 会调用 Targets数组中靠后的方法
  1. 直接调用 self.proxyRouter生成对象.
self.proxyRouter.targets = [self getModels];
//1.无参数 方法
[self.proxyRouter executeMethod:@"modelOneFunction"];
//2.无参数多个方法
[self.proxyRouter executeMethods:[self getMethods]];
//3.一个参数
[self.proxyRouter executeMethod:@"oneParamWith:" param:@"南风不竞"];
//4.多个参数
[self.proxyRouter executeMethod:@"modelTwoParam:bigName:" params:@[@"练峨眉",@"一页书"]];
//注:单个参数 方法名可以省略 :  多个参数方法名不可省略中间的:
  1. 直接调用 DEFAULT_ROUTER(单例)生成对象.
DEFAULT_ROUTER:[YHProxyRouter defaultRouter]
DEFAULT_ROUTER.targets = [self getModels];
//1.无参数 方法
[DEFAULT_ROUTER executeMethod:@"modelOneFunction"];
//2.无参数多个方法
[DEFAULT_ROUTER executeMethods:[self getMethods]];
//3.一个参数
[DEFAULT_ROUTER executeMethod:@"oneParamWith:" param:@"南风不竞"];
//4.多个参数
[DEFAULT_ROUTER executeMethod:@"modelTwoParam:bigName:" params:@[@"练峨眉",@"一页书"]];
//注:单个参数 方法名可以省略 :  多个参数方法名不可省略中间的:
  1. 直接调用 self.defaultRouter(单例)生成对象.
self.defaultRouter.targets = [self getModels];
//1.无参数 方法
[self.defaultRouter executeMethod:@"modelOneFunction"];
//2.无参数多个方法
[self.defaultRouter executeMethods:[self getMethods]];
//3.一个参数
[self.defaultRouter executeMethod:@"oneParamWith:" param:@"南风不竞"];
//4.多个参数
[self.defaultRouter executeMethod:@"modelTwoParam:bigName:" params:@[@"练峨眉",@"一页书"]];
//注:单个参数 方法名可以省略 :  多个参数方法名不可省略中间的:

版本 ChangeLog

V 1.0.0 (2017.11.04)

  • 首次提交!

V 1.0.1 (2017.11.07)

  • 增加单例模式, 增加取消类的注册接口.
/**
register single target with params
@param targetName targetName (NSString *)
*/
- (void)registerTargetName:(NSString *)targetName;

/**
unregister single target  params
@param targetName targetName (NSString *)
*/
- (void)unregisterTargetName:(NSString *)targetName;

/**
unregister all target without params
*/
- (void)unregisterAllTarget;

提示 Tips

  • self.proxyRouterinitWithTargets: 不能传入nil,否则会崩溃到断言NSAssert

  • 入参时 ,方法名中的: ,如果在字符串最后可以省略,如果在中间不可省略。

鸣谢 Thanks

  • YYKit

  • 海纳百川,有容乃大。感谢开源社区和众攻城狮的支持!感谢众多 IssuesPR!更期待你的 PR

联系 Support

许可 License

YHProxyRouter is released under the MIT License.

yhproxyrouter's People

Contributors

yuhechuan avatar

Stargazers

 avatar QinlingZhao avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.