Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kosoku/agamotto
Agamotto is an iOS/macOS/tvOS/watchOS framework that provides block based extensions to KVO and NSNotificationCenter.
https://github.com/kosoku/agamotto
ios kvo macos tvos watchos
Last synced: about 2 months ago
JSON representation
Agamotto is an iOS/macOS/tvOS/watchOS framework that provides block based extensions to KVO and NSNotificationCenter.
- Host: GitHub
- URL: https://github.com/kosoku/agamotto
- Owner: Kosoku
- License: mit
- Created: 2017-03-09T07:21:19.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-22T07:59:42.000Z (over 2 years ago)
- Last Synced: 2024-03-16T06:45:48.939Z (10 months ago)
- Topics: ios, kvo, macos, tvos, watchos
- Language: Objective-C
- Homepage:
- Size: 189 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## Agamotto
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Version](http://img.shields.io/cocoapods/v/Agamotto.svg)](http://cocoapods.org/?q=Agamotto)
[![Platform](http://img.shields.io/cocoapods/p/Agamotto.svg)]()
[![License](http://img.shields.io/cocoapods/l/Agamotto.svg)](https://github.com/Kosoku/Agamotto/blob/master/license.txt)*Agamotto* is an iOS/macOS/tvOS/watchOS framework that provides block based extensions to KVO and `NSNotificationCenter`. It handles tearing down the observer upon deallocation. It is based on part of the [ReactiveCocoa Objective-C framework](https://github.com/ReactiveCocoa/ReactiveObjC).
### Installation
You can install *Agamotto* using [cocoapods](https://cocoapods.org/), [Carthage](https://github.com/Carthage/Carthage), or as a framework.
### Usage
You **must** do the `weakSelf`/`strongSelf` dance for any blocks passed to the observing methods. Otherwise a retain cycle will be introduced.
It is not required in the notification observing example because `self` is not called within the block.
```objc
#importstatic NSNotificationName const kTextDidChangeNotification = @"kTextDidChangeNotification";
@interface MyObject : NSObject
@property (copy) NSString *text;- (void)foo;
@end@implementation MyObject
- (instancetype)init {
if (!(self = [super init]))
return nil;
__weak __typeof__(self) weakSelf = self;
[self KAG_addObserverForKeyPath:@"text" options:0 block:^(NSString *keyPath, id _Nullable value, NSDictionary *change){
__strong __typeof__(weakSelf) strongSelf = weakSelf;
[self foo];
}];
[self KAG_addObserverToNotificationCenter:nil notificationName:kTextDidChangeNotification object:self block:^(NSNotification *notification){
NSLog(@"notification %@",notification);
}];
return self;
}- (void)foo {
NSLog(@"text %@",self.text);
}- (void)setText:(NSString *)text {
_text = [text copy];
[[NSNotificationCenter defaultCenter] postNotificationName:kTextDidChangeNotification object:self];
}@end
```