Reputation: 3948
What is it?
I'm not sure I quite understand what this does.
- (NSString *)sectionIdentifier {
[self willAccessValueForKey:@"sectionIdentifier"];
NSString *tmp = [self primitiveSectionIdentifier];
[self didAccessValueForKey:@"sectionIdentifier"];
if (!tmp) {
tmp = @"bananas";
[self setPrimitiveSectionIdentifier:tmp];
}
return tmp;
}
How come I need this primitiveSectionIdentifier?
Ultimately, I'm using a example project from Apple's documentation to create a section identifier, to use with my NSFetchedResultsController.
While this does work. I am saying to myself that,
"sectionIdentifier" will be accessed, then I'm setting "tmp" to primitiveSectionIdentifier. But primitiveSectionIdentifier has nothing there at this point!! Does it?
I then say I did access "sectionIdentifier". But I can't see how that happened between "Will" and "Did"!
Can someone help me understand this?
Upvotes: 2
Views: 182
Reputation: 539925
[self primitiveSectionIdentifier]
is a so-called "primitive accessor" (see the Glossary of the Core Data Programming Guide). That is the function that actually fetches the value of the "sectionIdentifier" from the persistent store. The function is automatically created by the Core Data runtime.
willAccessValueForKey
and didAccessValueForKey
are "notification methods". According to the documentation, they are used for key-value observing, maintaining inverse relationships and so on.
So the pattern is:
Upvotes: 3