Need help with -mutableSetValueForKey:

  • I'm having difficulty implementing a kvc-compliant set property using
    methods.  Say I have an object with a property called 'things'. The
    documentation for -mutableSetValueForKey: specifies the additional
    methods required for 'things' to be a mutable set :

    - (void) addThingsObject:
    - (void) removeThingsObject:

    and refers to the documentation for -valueForKey: for the
    prerequisites of an immutable set.  These appear to be missing.  I
    have tried

    - (unsigned int) countOfThings;
    - (BOOL) containsThingsObject:(id)object;
    - (NSEnumerator *) thingsEnumerator;

    to no avail -- an exception complaining of non-compliance is raised on
    invoking [object mutableSetValueForKey:@"things"].

    Thanks in advance,

    dave
  • Hi,

    I think you want to implement:

    - countOfThings
    - objectInThingsAtIndex:
    - insertObject:inThingsAtIndex:
    - removeObjectFromThingsAtIndex:

    And you may want to also implement:

    - getThings:range:
    - replaceObjectInThingsAtIndex:withObject:

    Hope that helps,

    Wain

    On 21 Sep 2007, at 15:14, David Spooner wrote:

    >
    > I'm having difficulty implementing a kvc-compliant set property
    > using methods.  Say I have an object with a property called
    > 'things'. The documentation for -mutableSetValueForKey: specifies
    > the additional methods required for 'things' to be a mutable set :
    >
    > - (void) addThingsObject:
    > - (void) removeThingsObject:
    >
    > and refers to the documentation for -valueForKey: for the
    > prerequisites of an immutable set.  These appear to be missing.  I
    > have tried
    >
    > - (unsigned int) countOfThings;
    > - (BOOL) containsThingsObject:(id)object;
    > - (NSEnumerator *) thingsEnumerator;
    >
    > to no avail -- an exception complaining of non-compliance is raised
    > on invoking [object mutableSetValueForKey:@"things"].
    >
    > Thanks in advance,
    >
    > dave
  • According to the comment in NSKeyValueCoding.h (or Foundation Release
    notes for 10.4) you need to implement

    - (id) memberOfThings: (id) anObject

    (like the -member: method in NSSet).

    instead of containsThingsObject: .

    Cheers,

    felix

    On Sep 21, 2007, at 4:14 PM, David Spooner wrote:

    >
    > I'm having difficulty implementing a kvc-compliant set property
    > using methods.  Say I have an object with a property called
    > 'things'. The documentation for -mutableSetValueForKey: specifies
    > the additional methods required for 'things' to be a mutable set :
    >
    > - (void) addThingsObject:
    > - (void) removeThingsObject:
    >
    > and refers to the documentation for -valueForKey: for the
    > prerequisites of an immutable set.  These appear to be missing.  I
    > have tried
    >
    > - (unsigned int) countOfThings;
    > - (BOOL) containsThingsObject:(id)object;
    > - (NSEnumerator *) thingsEnumerator;
    >
    > to no avail -- an exception complaining of non-compliance is raised
    > on invoking [object mutableSetValueForKey:@"things"].
    >
    > Thanks in advance,
    >
    > dave
  • The answer is found in NSKeyValueCoding.h.  The required methods are:

    - (unsigned int) countOfThings;
    - (NSEnumerator *) enumeratorOfThings;
    - (id) memberOfThings:(id)thing;

    Thanks to all who responded.

    dave
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today