aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Shpakovski2013-04-16 04:45:55 -0700
committerVadim Shpakovski2013-04-16 04:45:55 -0700
commitb3e2e54830769c32c017c707793ddc30adc31798 (patch)
tree464a4e58dde70eb25641b88f9aca0fb89c9da5fd
parente5b32d7d47a0b69f76dbad6dfd4b7024ace5ced0 (diff)
parent7321b16163042c7fb4b73b21204a7cf6b1fa55fa (diff)
downloadMASShortcut-b3e2e54830769c32c017c707793ddc30adc31798.tar.bz2
Merge pull request #25 from corybohon/master
Adding a Notification section to the documentation.
-rw-r--r--README.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9776c35..e6cd2fd 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!
+#Notifications
+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 tasks.
+
+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).