Note that there are some explanatory texts on larger screens.

plurals
  1. POKVO on a collection
    primarykey
    data
    text
    <p>I added a observer to my collection, and observe the count on it</p> <pre><code>[[[JHTaskSave defaults] tasks] addObserver:self forKeyPath:@"count" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; </code></pre> <p>JHTaskSave is a singleton object and tasks is a JHTaskCollection KVC compliant, when I add an object to my collection:</p> <pre><code>[[[JHTaskSave defaults] tasks] addTask:newTask] </code></pre> <p>The count of tasks changes but the observeValueForKeyPath is not called, I don't understand why</p> <p>Here is my collection class:</p> <pre><code>@interface JHTaskCollection : NSObject &lt;NSFastEnumeration&gt; { NSMutableArray *_tasks; } @property (nonatomic) NSUInteger count; - (id)taskAtIndex:(NSUInteger)index; - (void)addTask:(JHTask *)task; - (void)removeTask:(JHTask *)task; - (void)insertObject:(id)key inTasksAtIndex:(NSUInteger)index; - (void)removeObjectFromTasksAtIndex:(NSUInteger)index; - (void)removeTaskAtIndexes:(NSIndexSet *)indexes; - (NSArray *)taskAtIndexes:(NSIndexSet *)indexes; @end @implementation JHTaskCollection - (id)init { if(self = [super init]) { _tasks = [[NSMutableArray alloc] init]; } return self; } - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len { return [_tasks countByEnumeratingWithState:state objects:stackbuf count:len]; } - (NSArray *)taskAtIndexes:(NSIndexSet *)indexes { return [_tasks objectsAtIndexes:indexes]; } - (void)insertObject:(id)key inTasksAtIndex:(NSUInteger)index { [_tasks insertObject:key atIndex:index]; } - (void)removeObjectFromTasksAtIndex:(NSUInteger)index { [_tasks removeObjectAtIndex:index]; } - (void)removeTaskAtIndexes:(NSIndexSet *)indexes { [_tasks removeObjectsAtIndexes:indexes]; } - (JHTask *)taskAtIndex:(NSUInteger)index { return [_tasks objectAtIndex:index]; } - (NSUInteger)count { return _tasks.count; } - (void)addTask:(JHTask *)task { [_tasks addObject:task]; } - (void)removeTask:(JHTask *)task { [_tasks removeObject:task]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload