GithubHelp home page GithubHelp logo

isabella232 / fsqmessageforwarder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from foursquare/fsqmessageforwarder

0.0 0.0 0.0 15 KB

An Obj-C message forwarder class, for when you don't have access to the source of the sending object.

License: Other

Ruby 5.73% Objective-C 94.27%

fsqmessageforwarder's Introduction

FSQMessageForwarder

Carthage compatible

An Obj-C message forwarder class, for when you don't have access to the source of the sending object.

Overview

The delegate pattern is very common in many Obj-C libraries, such as UIKit. However sometimes you want the ability to have more than one object receive delegate callbacks. FSQMessageForwarder acts as proxy delegate object, forwarding messages it receives to other objects.

Note: A test project is included but it is used for build testing only - an example application is currently not included in this repository.

Setup

You can include FSQMessageForwarder via Carthage (by adding github "foursquare/FSQMessageForwarder" to your Cartfile) or CocoaPods. Alternatively you can simply copy the h and m files for the class to your project manually.

Using Message Forwarder

There are two different flavors of message forwarder included. One manages its own array of weak references to child objects. The other uses an enumerator to manage its children which is provided to it by a delegate object that you set.

Either way, using the forwarder is simple. Just instantiate and retain the type of forwarder you want to use and setup its list of child objects. Usually you will then set the forwarder as the delegate of some other class (such as UITableView). The forwarder will forward any messages it does not itself implement to all of its children in order.

Calls to conformsToProtocol:, respondsToSelector:, and methodSignatureForSelector: will work as expected (eg. the forwarder conforms to a protocol if any of its children do, etc.).

If you yourself are writing the sending object, it is generally better to just write your code in such a way that it supports multiple delegates. FSQMessageForwarder is intended to be a workaround for 3rd-party classes that you do not have direct control over (such as those in UIKit)

Return Values

If a forwarded message has a return value, the return value of the first child to respond to the message will be used. If a later child would like its return value to be used instead, it can implement messageForwarder:shouldUseResponseForInvocation: to override this behavior.

Contributors

FSQMessageForwarder was initially developed by Foursquare Labs for internal use. It was originally written by Brian Dorfman (@bdorfman) and is currently maintained Sam Grossberg (@samgro).

fsqmessageforwarder's People

Contributors

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