Created
June 26, 2015 10:07
-
-
Save tkreuder/754ee005e54464fde665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ViewController () | |
@property (nonatomic,strong) TestController *controller; | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.controller=[[TestController alloc]init]; | |
[self.controller addObserver:self forKeyPath:NSStringFromSelector(@selector(hasAllAccountsSelected)) options:NSKeyValueObservingOptionNew context:NULL]; | |
} | |
-(void)dealloc | |
{ | |
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(hasAllAccountsSelected))]; | |
} | |
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context | |
{ | |
NSLog(@"%@",keyPath); | |
} | |
-(void)viewDidAppear:(BOOL)animated | |
{ | |
[self.controller fooBar]; | |
} | |
@end | |
@interface TestController : NSObject | |
@property (nonatomic,assign) BOOL hasAllAccountsSelected; | |
-(void)fooBar; | |
@end | |
@interface TestController () | |
@property (nonatomic,strong)NSMutableSet *selectedAccounts; | |
@end | |
@implementation TestController | |
-(instancetype)init | |
{ | |
self=[super init]; | |
if(self) | |
{ | |
_selectedAccounts=[NSMutableSet set]; | |
} | |
return self; | |
} | |
+ (NSSet *)keyPathsForValuesAffectingHasAllAccountsSelected | |
{ | |
return [NSSet setWithObjects:NSStringFromSelector(@selector(selectedAccounts)), nil]; | |
} | |
-(BOOL)hasAllAccountsSelected | |
{ | |
return self.selectedAccounts.count == [NSArray arrayWithObject:[[NSObject alloc]init]].count; | |
} | |
-(void)fooBar | |
{ | |
[self.selectedAccounts addObject:[[NSObject alloc]init]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment