Add pod MASShortcut 2.3.6

This commit is contained in:
Charlie Qiu
2017-03-10 22:35:50 +08:00
parent e003b89c2b
commit 52709213e4
57 changed files with 3504 additions and 373 deletions

View File

@ -0,0 +1,50 @@
#import "MASShortcutView+Bindings.h"
@implementation MASShortcutView (Bindings)
- (NSString*) associatedUserDefaultsKey
{
NSDictionary* bindingInfo = [self infoForBinding:MASShortcutBinding];
if (bindingInfo != nil) {
NSString *keyPath = [bindingInfo objectForKey:NSObservedKeyPathKey];
NSString *key = [keyPath stringByReplacingOccurrencesOfString:@"values." withString:@""];
return key;
} else {
return nil;
}
}
- (void) setAssociatedUserDefaultsKey: (NSString*) newKey withTransformer: (NSValueTransformer*) transformer
{
// Break previous binding if any
NSString *currentKey = [self associatedUserDefaultsKey];
if (currentKey != nil) {
[self unbind:currentKey];
}
// Stop if the new binding is nil
if (newKey == nil) {
return;
}
NSDictionary *options = transformer ?
@{NSValueTransformerBindingOption:transformer} :
nil;
[self bind:MASShortcutBinding
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:[@"values." stringByAppendingString:newKey]
options:options];
}
- (void) setAssociatedUserDefaultsKey: (NSString*) newKey withTransformerName: (NSString*) transformerName
{
[self setAssociatedUserDefaultsKey:newKey withTransformer:[NSValueTransformer valueTransformerForName:transformerName]];
}
- (void) setAssociatedUserDefaultsKey: (NSString*) newKey
{
[self setAssociatedUserDefaultsKey:newKey withTransformerName:NSKeyedUnarchiveFromDataTransformerName];
}
@end