Git Product home page Git Product logo

zdmediator's Introduction

ZDMediator

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

The run Test.m.

Requirements

Installation

ZDMediator is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ZDMediator'

Feature

  • 自动或手动注册
  • 自主控制生命周期
  • 实例方法、类方法
  • 事件分发
  • 一个对象对应多个协议
  • 一个协议多个对象对应
  • 安全

Usage

更多用例请查看Test.m文件

  • 注册
/// 自动注册
ZDMediatorOFARegister(CatProtocol, ZDCat, 10)

//⚠️ 如果是一对多(一个协议多个对象遵守),priority一定不能重复,
//⚠️ 如下面的cat和dog不能使用同一个priority
ZDMediatorOFARegister(AnimalProtocol, ZDCat, 0)
ZDMediatorOFARegister(AnimalProtocol, ZDDog, 1)

 ------

/// 手动注册
ZDCat *cat = [ZDCat new];
[ZDMOneForAll manualRegisterService:@protocol(CatProtocol) priority:1 implementer:cat weakStore:YES];
  • 读取
// 通过priority拿到的是dog对象,如果不传则默认取数组中第一个
NSString *animalName = [GetServiceWithPriority(AnimalProtocol, 1) animalName];
XCTAssertTrue([animalName isEqualToString:@"小狗"]);

结构

architecture

粗略流程

process

Q&A

  1. priority是做什么用的?

    查表key的一部分,是必须要设置的

  2. 如何保证安全性的?

    执行方法调用的其实是proxy对象,内部通过消息转发把异常吃掉了

Author

Zero.D.Saber, [email protected]

License

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

zdmediator's People

Contributors

faimin avatar

Watchers

 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.