TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
While NSNotification is easy to use, it has the following drawbacks:
HUTypedEvents provides an alternative solution to passing events in Objective C. The events are based on methods, and all the parameters are strongly typed. All the event triggering and handling code can take the advantage of compiler check and Xcode autocompletion.
For example, there is an event called EventX, it passes two params: (int)x and (float)y
Create a centralized event handler class, make it a singleton and declare/implement the event logic through the helper methods:
CentralHandler.h:
HUDeclareEvent(EventX, x:(int)x y:(float)y)
@interface CentralHandler : NSObject
HUDeclareSingleton(CentralHandler);
HUDeclareEventRegistation(EventX, x:(int)x y:(float)y);
@end
CentralHandler.m:
@implementation CentralHandler : NSObject <ProtocolForEventB>
HUImplementSingleton(CentralHandler);
HUImplementEvent(EventX, x:(int)x y:(float)y);
@end
Call this anywhere:
[[CentralHandler instance] handleEventX_x:someX y:someY];
Make the object conform to EventX, and implement the protocol method
- (void) handleEventX_x:(int)x y:(float)y;
In the initialization method, call:
[[CentralHandler instance] registerEventX_object:self];