Latest | 0.1.0 |
---|---|
Homepage | https://github.com/sleroux/KVO-Blocks |
License | MIT Copyright (C) 2013 Stephan Leroux
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Platforms | ios , requires ARC |
Authors |
KVO Blocks – Bringing KVO into the modern world
Idea
Tired of having a giant observeForKeyPath method that is just filled with if statements for determining which value actually changed? Wish there was a better way? Blocks are a great way to encapsulate tidbits of functionality – why not combine the power of KVO with the modularity of blocks?
Wait no more
By adding a super simple category to your NSObject class you too can experience cleaner KVO code while avoiding those nested if statements.
Setup
To add to your project using CocoaPods, add the following to your Podfile:
pod 'KVOBlocks'
Alternatively, you can also just copy the single category class from the KVO Blocks directory and add directly into your project.
Usage
To get started with using blocks as your observer, you can use the similiar method signature as the original addObserver method
[model addObserver:self forKeyPath:@"keyname" options:NSKeyValueObservingOptionsNew context:nil withBlock:^(NSDictionary *change, void *context) {
// Handle KVO change on this keyname
}];
Similarly, to remove the observer you can call as you normally would:
[model removeBlockObserver:self forKeyPath:@"keyname"];
Feedback
If theres any questions or concerns, feel free to let me know – this is just small something I put together to help de-clutter my code so any suggestions are welcome!
License
This software package is under MIT license.
Latest podspec
{ "name": "KVOBlocks", "version": "0.1.0", "summary": "Bringing KVO into the modern world by using blocks.", "homepage": "https://github.com/sleroux/KVO-Blocks", "license": { "type": "MIT", "text": " Copyright (C) 2013 Stephan Lerouxnn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:nn The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.nn THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.n" }, "authors": { "Stephan Leroux": "[email protected]" }, "source": { "git": "https://github.com/sleroux/KVO-Blocks.git", "tag": "0.1.0" }, "platforms": { "ios": null }, "source_files": [ "KVO Blocks", "KVO Blocks/*.{h,m}" ], "requires_arc": true }
Tue, 01 Mar 2016 07:54:03 +0000