I have a Core Data property that I am trying to set at runtime, with a value obtained from another property. However, with curiosity, the custom accessory that I built does not even seem evoked.
The seasonNameVisible property, called only from the predicate with terms from the search field, as shown here:
// Add our search predicates for (NSString *term in searchTerms) { NSPredicate *searchTermPredicate = [NSPredicate predicateWithFormat:@"(episodeName contains[cd] %@) OR (fromSeason.seasonNameVisible contains[cd] %@) OR (fromSeason.fromSeries.seriesName contains[cd] %@)", term, term, term]; [subPredicates addObject:searchTermPredicate]; }
If I changed this property to seasonName , this part of the predicate will return the result just fine, so I don't suspect a predicate or any other search code.
My plan is to infer seasonNameVisible NSString from seasonName at runtime. So, I changed the subclass of Season NSManagedObject to override accessor and setter using primitive accessors. But as far as I can tell, my accessory is never called.
Here is the header / interface:
// // Season.h // #import <Foundation/Foundation.h>
... and implementation:
// // Season.m // #import "Season.h" #import "Episode.h" #import "Series.h" @implementation Season @dynamic seasonIndex; @dynamic seasonName; @dynamic seasonNameVisible; @dynamic episodes; @dynamic fromSeries; // my additions @dynamic primitiveSeasonName; @dynamic primitiveSeasonNameVisible; - (NSString *)seasonNameVisible { NSString *visible; [self willAccessValueForKey:@"seasonNameVisible"]; visible = [self primitiveValueForKey:@"seasonNameVisible"]; [self didAccessValueForKey:@"seasonNameVisible"]; if (visible != nil) { return visible; } else { [self willAccessValueForKey:@"seasonName"]; visible = [[self primitiveValueForKey:@"seasonName"] substringFromIndex:2]; [self didAccessValueForKey:@"seasonName"]; [self setSeasonNameVisible:visible]; return visible; } } - (void)setSeasonNameVisible:(NSString *)seasonNameVisible { [self willChangeValueForKey:@"seasonNameVisible"]; [self setPrimitiveValue:seasonNameVisible forKey:@"seasonNameVisible"]; [self didChangeValueForKey:@"seasonNameVisible"]; } @end
I read Apple docs and looked for help using special StackOverflow access methods, and I think I have the correct code (this is the first time I have tried using primitive accessors or overriding NSManagedObject, so I'm lagging a bit behind my usual depth) but even when I put a breakpoint on it, it never calls a call.