{"id":16203299,"url":"https://github.com/sschmid/floc-dispatcher","last_synced_at":"2025-03-19T07:30:46.943Z","repository":{"id":9419091,"uuid":"11289251","full_name":"sschmid/Floc-Dispatcher","owner":"sschmid","description":"An alternative to NSNotificationCenter.","archived":false,"fork":false,"pushed_at":"2013-07-17T20:13:05.000Z","size":260,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T16:18:05.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sschmid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-09T17:43:47.000Z","updated_at":"2023-07-03T16:50:06.000Z","dependencies_parsed_at":"2022-07-08T02:10:40.955Z","dependency_job_id":null,"html_url":"https://github.com/sschmid/Floc-Dispatcher","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Dispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Dispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Dispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sschmid%2FFloc-Dispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sschmid","download_url":"https://codeload.github.com/sschmid/Floc-Dispatcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976658,"owners_count":20377695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T09:53:42.221Z","updated_at":"2025-03-19T07:30:46.513Z","avatar_url":"https://github.com/sschmid.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Floc Dispatcher\n![Floc Dispatcher Logo](http://sschmid.com/Dev/iOS/Libs/Floc-Dispatcher/Floc-Dispatcher-128.png)\n[![Build Status](https://travis-ci.org/sschmid/Floc-Dispatcher.png?branch=master)](https://travis-ci.org/sschmid/Floc-Dispatcher)\n\n## Description\nAn alternative to NSNotificationCenter.\n\n## Features\n* Dispatch any object (no NSNotification like in NSNotificationCenter)\n* Add observers with priority\n* Add observers that get removed after execution (add once)\n\n## How to use Floc Dispatcher\n\n#### Get a dispatcher\n\n```objective-c\n// Create your own dispatcher\nGDDispatcher *dispatcher = [[GDDispatcher alloc] init];\n\n// or use the shared dispatcher\nGDDispatcher *dispatcher = [GDDispatcher sharedDispatcher];\n```\n\n#### Add observers\n\n```objective-c\n[dispatcher addObserver:self forObject:[Greeting class]\n           withSelector:@selector(doSthLast:) priority:-5];\n\n[dispatcher addObserver:self forObject:[Greeting class]\n           withSelector:@selector(doSthFirst:) priority:10];\n```\n\nYou can add observers that get removed after execution\n\n```objective-c\n[dispatcher addObserverOnce:self forObject:[Greeting class]\n           withSelector:@selector(doSthLast:) priority:-5];\n\n[dispatcher addObserverOnce:self forObject:[Greeting class]\n           withSelector:@selector(doSthFirst:) priority:10];\n```\n\n#### Dispatch objects\n\n```objective-c\n[dispatcher dispatchObject:[[Greeting alloc] initWithString:@\"Hello\"]];\n\n// Logs\n// Got greeting first: Hello\n// Got greeting last: Hello\n```\n\n```objective-c\n- (void)doSthFirst:(Greeting *)greeting {\n    NSLog(@\"Got greeting first: %@\", greeting.string);\n}\n\n- (void)doSthLast:(Greeting *)greeting {\n    NSLog(@\"Got greeting last: %@\", greeting.string);\n}\n```\n\n## Example\n\nIn this example a fake service simulates fetching some data from a remote server. It dispatches the response. An other class\nis observing objects of type `User`. If an `User` gets dispatched somewhere in the application, the observer gets\nnotified and the target selector gets performed. `fl_dispatcher_add`, `fl_dispatcher_remove` and `fl_dispatcher_dispatch`\nare some convenience macros available in Floc Dispatcher.\n\n```objective-c\n@interface Example ()\n@property(nonatomic, strong) Service *service;\n@end\n\n@implementation Example\n\n- (id)init {\n    self = [super init];\n    if (self) {\n        fl_dispatcher_add(self, [User class], @selector(updateWithUser:));\n\n        self.service = [[Service alloc] init];\n        [self.service login];\n    }\n\n    return self;\n}\n\n- (void)updateWithUser:(User *)user {\n    NSLog(@\"user.name = %@\", user.name);\n    NSLog(@\"user.age = %u\", user.age);\n}\n\n- (void)dealloc {\n    fl_dispatcher_remove(self);\n}\n\n@end\n```\n\n```objective-c\n@implementation Service\n\n- (void)login {\n    [self performSelector:@selector(remoteServerResponded) withObject:nil afterDelay:0.5];\n}\n\n- (void)remoteServerResponded {\n    User *user = [[User alloc] init];\n    user.name = @\"Joe\";\n    user.age = 28;\n    fl_dispatcher_dispatch(user);\n}\n\n@end\n```\n\n## Install Floc Dispatcher\nYou find the source files you need in Floc-Dispatcher/Classes.\n\n## CocoaPods\nInstall [CocoaPods] (http://cocoapods.org) and add the Floc Dispatcher reference to your Podfile\n\n```\nplatform :ios, '5.0'\n  pod 'Floc-Dispatcher'\nend\n```\n\n#### Install Floc Dispatcher\n\n```\n$ cd path/to/project\n$ pod install\n```\nOpen the created Xcode Workspace file.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsschmid%2Ffloc-dispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsschmid%2Ffloc-dispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsschmid%2Ffloc-dispatcher/lists"}