• 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
CORE DATA, mutableSetValueForKey: on transient properties returns nil ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CORE DATA, mutableSetValueForKey: on transient properties returns nil ?


  • Subject: CORE DATA, mutableSetValueForKey: on transient properties returns nil ?
  • From: AurĂ©lien HugelĂ© <email@hidden>
  • Date: Wed, 29 Mar 2006 12:05:28 +0200

Hi list !

i have a **transient** property in my schema, which is an NSMutableSet (please do not ask why i did'nt use relationships, there is a valid reason!)
i've implemented my accessors like this :


- (NSSet*)externalLinks
{
[self willAccessValueForKey:@"externalLinks"];
NSSet *externalLinks = [self primitiveValueForKey:@"externalLinks"];
[self didAccessValueForKey:@"externalLinks"];
if (externalLinks == nil) {
NSData *externalLinksData = [self valueForKey:@"externalLinksData"];
if (externalLinksData != nil) {
externalLinks = [[NSUnarchiver unarchiveObjectWithData:externalLinksData] retain]; // over retain, will be released below
}
else {
externalLinks = [[NSMutableSet alloc] init];
}

[self setPrimitiveValue:externalLinks forKey:@"externalLinks"];

[externalLinks release]; // compensate alloc/init or over retain above
}
return externalLinks;
}


- (void)setExternalLinks:(NSSet *)aSet
{
    [self willChangeValueForKey:@"externalLinks"];
    [self setPrimitiveValue:aSet forKey:@"externalLinks"];
    [self didChangeValueForKey:@"externalLinks"];
}

What is important here, is that when you ask for externalLinks, the NSMutableSet is dearchived if there is one, then cached in the transient property, OR IF THERE WAS NO DATA TO DEARCHIVE, AN EMPTY NSMUTABLESET IS CREATED.

externalLinks should then never return nil !

now, in my code
// myManagedObject is a fresh managed object that does not have any externalLinksData.
[myManagedObject externalLinks] returns an empty set, as desired
[myManagedObject valueForKey:@"externalLinks"] returns an empty set, as desired
[myManagedObject mutableSetValueForKey:@"externalLinks"] returns nil IF NONE OF THE METHODS ABOVE HAVE BEEN CALLED BEFORE. I mean that calling [myManagedObject externalLinks] then [myManagedObject mutableSetValueForKey:@"externalLinks"] make [myManagedObject mutableSetValueForKey:@"externalLinks"] return an empty set. But calling [myManagedObject mutableSetValueForKey:@"externalLinks"] for the first time returns nil. My accessors are not called.


is it a bug in mutableSetValueForKey: NSManagedObject implementation ?
it seems that mutableSetValueForKey: NSManagedObject implementation does not check for accessors, but instead "analyse" the managed object structure and return nil if the internal structure shows that the property for the given key is transient...
thanks for any help
_______________________________________________
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: Dragging promised files to finder behaviour question
  • Next by Date: Re: DoubleAction in an empty Table...
  • Previous by thread: Re: Dragging promised files to finder behaviour question
  • Next by thread: NSAppleScript and script editor
  • Index(es):
    • Date
    • Thread