CMSignals
Qt Signals and Slots clone to Objective-C.
Install / Use
/learn @edgurgel/CMSignalsREADME
CMSignals
Qt Signals and Slots clone to Objective-c
Example
A class with a signal.
#import <Foundation/Foundation.h>
#import "NSObject+CMSignals.h"
@protocol CMExampleSignals
CM_signals
- (void)signalMethod:(NSString *)string andNumber:(NSNumber *)number;
@end
@interface CMExample : NSObject <CMExampleSignals>
@end
A class with a slot
#import <Foundation/Foundation.h>
#import "NSObject+CMSignals.h"
@class CMExample;
@interface CMExampleReceiver : NSObject
- (id)initWithExample:(CMExample *)example;
- (void)slotMethod:(NSString *)string andNumber:(NSNumber *)number;
@end
#import "CMExampleReceiver.h"
@implementation CMExampleReceiver
- (id)initWithExample:(CMExample *)example
{
self = [super init];
if (self) {
[self connect:@selector(signalMethod:andNumber:)
from:example
with:@selector(slotMethod:andNumber:)];
}
return self;
}
- (void)slotMethod:(NSString *)string andNumber:(NSNumber *)number
{
NSLog(@"Slot called: %@ - %@", [number description], string);
}
@end
Somewhere on CMExample we execute:
[self emit:@selector(signalMethod:andNumber:) withArguments:@[ @"Codeminer", [NSNumber numberWithInt:42]]];
And we get the slotMethod called.
Note that one can use the category on NSObject or use the singleton class CMSignals to connect, disconnect and emit signals/slots
Why not NSNotificationCenter?
- Signal is a method definition;
- Slot is a method;
- No NSNotification treatment;
- No userInfo dictionary;
- Classes describe a well defined signal protocol.
CMSignals actually use NSNotificationCenter under the hood. CMSignals remove the boilerplate.
TODO
[ ]Send broadcast signals using a class instead of an object;[✓]<del>Make it a CocoaPod.</del>
Credits
CMSignals was created by Eduardo Gurgel and Tiago Bastos.
Many thanks to Codeminer 42.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
