Latest 1.0.5
Homepage https://github.com/muccy/MUKSignal
License MIT
Platforms ios 7.0, requires ARC
Authors

CI Status
Version
License
Platform

MUKSignal provides a mechanism to dispatch a signal to various subscribers.

Main features

MUKSignal is a simple class which exposes three main features.

Dispatch

You can dispatch a signal with a payload.

MUKSignal<NSString *> *signal = [[MUKSignal alloc] init];
...
[signal dispatch:@"Hello"];

Subscribtion

You could add subscribers to a signal.

id const token = [signal subscribe:^(NSString *payload) {
    // Called after dispatch
}];

Suspension

A subscription could be temporarily suspended.

[signal suspend:token];
// Dispatches are not delivered
[signal resume:token];
// If a dispatch has occurred during suspension is delivered now (if more than one they are coalesced into one)

Specific signals

Library includes specific signals which are dispatched in particular conditions.

KVO

KVO signals observe an object and are dispatched when a change occurs.

MUKKVOSignal<NSString *> *signal = [[MUKKVOSignalChange alloc] initWithObject:self keyPath:@"name"];
[signal subscribe:^(MUKKVOSignalChange<NSString *> change) {
    NSLog(@"Name changed from '%@' to '%@'", change.oldValue, change.value);
}];

Notification

Notification signals are dispatched when a notification fires.

MUKNotificationSignal *signal = [[MUKNotificationSignal alloc] initWithName:name:UIApplicationWillEnterForegroundNotification object:nil];
[signal subscribe:^(NSNotification *notification) {
    // App will enter foreground
}];

UIControl target-action

Control action signals are dispatched when action for a control is triggered.

MUKControlActionSignal<UIButton *> *signal = [[MUKControlActionSignal alloc] initWithControl:self.button forEvents:UIControlEventTouchUpInside];
[signal subscribe:^(UIEvent *event) {
    // Called when button has been pressed
}];

Observation

Observation is the concept to couple a signal to a particular subscription. It is particular useful when you have many signals to observe not to bloat your view controller.

MUKSignal *signal = ...;
MUKSignalObservation *observation = [MUKSignalObservation observationWithSignal:signal token:[signal subscribe:^(id payload) 
{
    // Waiting for a dispatch
}]];

Requirements

  • iOS 7 SDK.
  • Minimum deployment target: iOS 7.

Installation

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

pod "MUKSignal"

Author

Marco Muccinelli, [email protected]

License

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

Latest podspec

{
    "name": "MUKSignal",
    "version": "1.0.5",
    "summary": "Dispatch signals which could be subscribed by various subscribers.",
    "description": "Dispatch signals which could be subscribed by various subscribers. Subscription could also be suspended. This library also contains specific signals, like notification signals, KVO signals and control target-action signals.",
    "homepage": "https://github.com/muccy/MUKSignal",
    "license": "MIT",
    "authors": {
        "Marco Muccinelli": "[email protected]"
    },
    "source": {
        "git": "https://github.com/muccy/MUKSignal.git",
        "tag": "1.0.5"
    },
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/**/*.{h,m}"
}

Pin It on Pinterest

Share This