Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.m
- // KVOTest
- //
- // Created by Ilya Kulakov on 04.07.12.
- // Copyright (c) 2012 kulakov.ilya@gmail.com. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @interface ObjectWithArray : NSObject
- @property (copy) NSArray *array;
- @end
- @interface TopObject : NSObject
- @property (retain) ObjectWithArray *property;
- @end
- @interface Observer : NSObject
- @end
- #pragma mark -
- @implementation ObjectWithArray
- @synthesize array;
- @end
- @implementation TopObject
- @synthesize property;
- @end
- @implementation Observer
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- {
- NSLog(@"Path: %@", keyPath);
- NSLog(@"Change: %@", change);
- }
- @end
- #pragma mark -
- int main(int argc, const char * argv[])
- {
- @autoreleasepool {
- ObjectWithArray *o1 = [[ObjectWithArray new] autorelease];
- TopObject *o2 = [[TopObject new] autorelease];
- Observer *o3 = [[Observer new] autorelease];
- [o2 addObserver:o3 forKeyPath:@"property.array" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:NULL];
- o2.property = o1;
- o1.array = [NSArray arrayWithObject:@"mamba"];
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment