CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

MUKSignal 1.1

MUKSignal 1.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Oct 2019

Maintained by Marco Muccinelli.



  • By
  • Marco Muccinelli

MUKSignal

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.

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.