https://github.com/sschmid/gummi-dispatcher
Observe and dispatch any objects
https://github.com/sschmid/gummi-dispatcher
Last synced: 12 months ago
JSON representation
Observe and dispatch any objects
- Host: GitHub
- URL: https://github.com/sschmid/gummi-dispatcher
- Owner: sschmid
- License: mit
- Created: 2013-01-10T15:52:00.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-03-18T21:23:36.000Z (over 13 years ago)
- Last Synced: 2025-02-13T20:52:12.474Z (over 1 year ago)
- Language: Objective-C
- Homepage: http://sschmid.github.com/Gummi-Dispatcher/
- Size: 363 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Gummi Dispatcher

## Description
Observe and dispatch any objects.
## Features
* Dispatch any object (no NSNotification like in NSNotificationCenter)
* Add observers with priority
* Add observers that get removed after execution (add once)
## How to use Gummi Dispatcher
#### Get a dispatcher
```objective-c
// Create your own dispatcher
GDDispatcher *dispatcher = [[GDDispatcher alloc] init];
// or use the shared dispatcher
GDDispatcher *dispatcher = [GDDispatcher sharedDispatcher];
```
#### Add observers
```objective-c
[dispatcher addObserver:self forObject:[Greeting class]
withSelector:@selector(doSthLast:) priority:-5];
[dispatcher addObserver:self forObject:[Greeting class]
withSelector:@selector(doSthFirst:) priority:10];
```
You can add observers that get removed after execution
```objective-c
[dispatcher addObserverOnce:self forObject:[Greeting class]
withSelector:@selector(doSthLast:) priority:-5];
[dispatcher addObserverOnce:self forObject:[Greeting class]
withSelector:@selector(doSthFirst:) priority:10];
```
#### Dispatch objects
```objective-c
[dispatcher dispatchObject:[[Greeting alloc] initWithString:@"Hello"]];
// Logs
// Got greeting first: Hello
// Got greeting last: Hello
```
```objective-c
- (void)doSthFirst:(Greeting *)greeting {
NSLog(@"Got greeting first: %@", greeting.string);
}
- (void)doSthLast:(Greeting *)greeting {
NSLog(@"Got greeting last: %@", greeting.string);
}
```
## Install Gummi Dispatcher
You find the source files you need in Gummi-Dispatcher/Classes.
## CocoaPods
Install [CocoaPods] (http://cocoapods.org) and add the Gummi Dispatcher reference to your Podfile
```
platform :ios, '5.0'
pod 'Gummi-Dispatcher'
end
```
#### Add this remote
```
$ pod repo add sschmid-cocoapods-specs https://github.com/sschmid/cocoapods-specs
```
#### Install Gummi Dispatcher
```
$ cd path/to/project
$ pod install
```
Open the created Xcode Workspace file.
## Projects that use Gummi Dispatcher
* [Gummi Commander] (https://github.com/sschmid/Gummi-Commander) Event Command Mapping System for Objective-C