• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
distinctUnionOfSets operator with mutableSetValueForKeyPath:?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

distinctUnionOfSets operator with mutableSetValueForKeyPath:?


  • Subject: distinctUnionOfSets operator with mutableSetValueForKeyPath:?
  • From: "Jeremy Higgs" <email@hidden>
  • Date: Thu, 2 Nov 2006 16:42:15 +1100

Hi all,

I'm in the process of moving an application towards bindings and
CoreData (well, it's mostly done). However, I'm having an issue with
some array/set operators and Key-Value Coding.

I've got an object with the following relationships (and cardinality marked):

Object A (1) --- (M) Object B (1) --- (M) Object C

That is, Object A can have many instances of Object B, and Object B
can have many instances of Object C.

What I'm trying to do (in an accessor method) is achieve this:

Object A (1) --- (M) Object C

In my accessor method, I have the following:

- (NSSet *)allObjectC;
{
	return [self valueForKeyPath:@"email@hiddentC"];
}

This works fine. As I understand it, the valueForKeyPath: call above
works in the following way:

1) Calls [self valueForKey:@"objectB"] on objectA (which returns a set)
2) For each of the objects in the set, valueForKey:@"objectC" is called
3) The results of 2) are aggregated into a set and returned. (So
there's a set containing instances of Object C.)

I've got tests for this, so am confident that's what the result is.

However, if I want to retrieve a mutable set containing those objects
(mutableSetValueForKeyPath:), I have problems using the
@distinctUnionOfSets operator. The following is the "mutable" version
of the method I pasted above:

- (NSMutableSet *) allObjectC;
{
	return [self mutableSetValueForKeyPath:@"objectB.@distinctUnionOfSets.
objectC"];
}

Calling this method results in the following message:

[<NSCFSet 0x5f99b10> valueForUndefinedKey:]: this class is not key
value coding-compliant for the key distinctUnionOfSets.

As far as I can see, there's nothing in the documentation (
http://tinyurl.com/ylh9ck ) that says you can't use the set and array
operators with mutableSetValueForKeyPath: .

Funnily enough, the what is returned by the "immutable" use of
valueForKeyPath: appears to be a mutable set. This contrasts the KVC
documentation (http://tinyurl.com/yloj3c ):

"The default implementation recognizes the same simple accessor
methods and set accessor methods as valueForKey:, and follows the same
direct instance variable access policies, but always returns a mutable
collection proxy object instead of the immutable collection that
valueForKey: would return."

Am I misunderstanding some of the concepts here, or is it a problem in KVC?

Thanks in advance!

Jeremy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: swizzling a class to a subclass inorder to add ivars (& methods) to a class
  • Next by Date: Re: Core data, array controller, and add:
  • Previous by thread: Re: swizzling a class to a subclass inorder to add ivars (& methods) to a class
  • Next by thread: Re: Simulate Photoshop's "Overlay" compositing method
  • Index(es):
    • Date
    • Thread