From 75c763f6973985710e5142031c5673580b61064f Mon Sep 17 00:00:00 2001 From: Cory Bohon Date: Mon, 15 Apr 2013 23:15:32 -0300 Subject: Update README.md Updated the documentation to cover NSUserDefaults observing.--- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 9776c35..5f70798 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,28 @@ I hope, it is really easy: To set an example, I made a demo project: [MASShortcutDemo](https://github.com/shpakovski/MASShortcutDemo). Enjoy! +#Notification of Change +By registering for NSNotifications from NSUserDefaults observing, you can get a callback whenever a user changes the shortcut, allowing you to perform any UI updates, or other code handling needs. + +This is just as easy to implement: + //implement when loading view + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults addObserver:self + forKeyPath:kPreferenceGlobalShortcut + options:NSKeyValueObservingOptionNew + context:NULL]; + + //capture the KVO change and do something + - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context + { + NSLog(@"KVO changed"); + } + + + //don't forget to remove the observer + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults removeObserver:self forKeyPath:kPreferenceGlobalShortcut]; + # Non-ARC Version If you like retain/release, please check out these forks: [heardrwt/MASShortcut](https://github.com/heardrwt/MASShortcut) and [chendo/MASShortcut](https://github.com/chendo/MASShortcut). -- cgit v1.2.3