Guest User

Untitled

a guest
Jun 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. [myObj addObserver:self forKeyPath:@"theArray" options:0 context:NULL];
  2.  
  3. [myObj.theArray addObject:NSString.string];
  4.  
  5. [[myObj mutableArrayValueForKey:@"theArray"] addObject:NSString.string];
  6.  
  7. [myObject insertObject:newObject inTheArrayAtIndex:[myObject countOfTheArray]];
  8.  
  9. - (void) addTheArrayObject:(NSObject *) newObject {
  10. [self insertObject:newObject inTheArrayAtIndex:[self countOfTheArray]];
  11. }
  12.  
  13. [myObj addObserver:self forKeyPath:@"theArray.@count" options:0 context:NULL];
  14.  
  15. - (NSMutableArray*) theMutableArray {
  16. return [self mutableArrayValueForKey:@"theArray"];
  17. }
  18.  
  19. // Interface
  20. @property (nonatomic, strong, readonly) NSMutableArray *items;
  21.  
  22. // Implementation
  23. @synthesize items = _items;
  24.  
  25. - (NSMutableArray *)items
  26. {
  27. return [self mutableArrayValueForKey:@"items"];
  28. }
  29.  
  30. // Somewhere else
  31. [myObject.items insertObject:@"test"]; // Will result in KVO notifications for key "items"
  32.  
  33. - (void)addSomeObject:(id)object {
  34. self.myArray = [self.myArray arrayByAddingObject:object];
  35. }
  36.  
  37. - (void)removeSomeObject:(id)object {
  38. NSMutableArray * ma = [self.myArray mutableCopy];
  39. [ma removeObject:object];
  40. self.myArray = ma;
  41. }
Add Comment
Please, Sign In to add comment