Key-Value-Observing and Collections

Fabian Schuiki fabianschuiki at bluewin.ch
Thu Oct 25 07:35:12 PDT 2007


Hi,

Call [self willChangeValueForKey:@"grades"] at the beginning of - 
(void)addGrade: and [self didChangeValueForKey:@"grades"] just when  
you changed the grades variable.

Best,
Fabian

Fabian Schuiki
fabianschuiki at bluewin.ch


Am 25.10.2007 um 15:23 schrieb Philip Mötteli:

> Hi,
>
>
> There is something, I just don't get with KVO. Lets say, I have an  
> object
>
>
> @interface Pupil
> {
> 	NSMutableArray	grades;
> }
>
>
> - (void)setGrades:(NSMutableArray *)theGrades;
> - (NSMutableArray *)grades;
> - (void)addGrade:(Grade *)aGrade;
>
> @end
>
>
> Using KVO, I want to be notified not only, when the old grades  
> collection object (NSMutableArray) is replaced, but also, when a  
> Grade instance is added to the grades array (something like  
> "[grades addObject:aGrade]").
> The first case is easy, because I know the attribute name (grades),  
> which gives the key. But for the second, I don't know the attribute  
> name, so I can't add an observer.
> Can anybody explain me how to do this?
>
>
> Thanks
> Phil
>
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev at omnigroup.com
> http://www.omnigroup.com/mailman/listinfo/macosx-dev



More information about the MacOSX-dev mailing list