Skip to content

Instantly share code, notes, and snippets.

@erica
Last active August 29, 2015 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erica/68e68a8239d5cf71211a to your computer and use it in GitHub Desktop.
Save erica/68e68a8239d5cf71211a to your computer and use it in GitHub Desktop.
Playground Toybox - Mac Helper
NSString *const ToyboxNotification = @"com.sadun.ToyboxNotification";
NSString *const kIdentity = @"kIdentity";
NSString *const kTrigger = @"kTrigger";
NSString *const kString = @"kString";
NSString *const kValue = @"kValue";
NSString *const kRadio = @"kRadio";
NSString *const kRadioRow = @"kRadioRow";
NSString *const kRadioColumn = @"kRadioColumn";
@implementation AppDelegate
- (IBAction)postRadio:(NSMatrix <NSUserInterfaceItemIdentification> *)sender
{
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kRadio userInfo:@{kIdentity:sender.identifier, kRadioRow:@(sender.selectedRow), kRadioColumn:@(sender.selectedColumn)}];
[[NSDistributedNotificationCenter defaultCenter] postNotification:note];
}
- (IBAction)postString:(NSTextField <NSUserInterfaceItemIdentification> *)sender
{
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kString userInfo:@{kIdentity:sender.identifier, kString:sender.stringValue}];
[[NSDistributedNotificationCenter defaultCenter] postNotification:note];
}
- (IBAction)postValue:(NSControl <NSUserInterfaceItemIdentification> *)sender
{
NSNumber *value = @(0);
if ([sender respondsToSelector:@selector(floatValue)])
{
NSSlider *slider = (NSSlider *) sender;
value = @(slider.floatValue);
}
else if ([sender respondsToSelector:@selector(state)])
{
NSButton *button = (NSButton *) sender;
value = @([button state] == NSOnState);
}
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kValue userInfo:@{kIdentity:sender.identifier, kValue:value}];
[[NSDistributedNotificationCenter defaultCenter] postNotification:note];
}
- (IBAction)trigger:(id <NSUserInterfaceItemIdentification>)sender
{
NSNotification *note = [NSNotification notificationWithName:ToyboxNotification object:kTrigger userInfo:@{kIdentity:sender.identifier}];
[[NSDistributedNotificationCenter defaultCenter] postNotification:note];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment