CORE DATA, mutableSetValueForKey: on transient properties returns nil ?
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