I implemented the transient property, as shown below, on one of the models of my application. It is declared in model design as a transient property of type undefined.
@property (nonatomic, readonly) NSNumberFormatter *currencyFmt;
Current (warning) type of this accessory:
- (NSNumberFormatter *) currencyFmt { [self willAccessValueForKey:@"currencyFmt"]; NSNumberFormatter *fmt = [self primitiveValueForKey:@"currencyFmt"]; [self didAccessValueForKey:@"currencyFmt"]; if (fmt == nil) { fmt = [[[NSNumberFormatter alloc] init] autorelease]; [fmt setNumberStyle:NSNumberFormatterCurrencyStyle]; [fmt setLocale:[self localeObject]]; [self setPrimitiveValue:fmt forKey:@"currencyFmt"]; } return fmt; }
The call to primitiveValueForKey: is a problem here, since the documentation specifically warns about using this version of primitive search:
You are strongly encouraged to use dynamically generated than using this method directly (for example, primitiveName: instead of primitiveValueForKey: @ "name"). dynamic accessors are much more efficient and allow compile-time validation.
The problem is that if I try to use primitiveCurrencyFmt instead of primitiveValueForKey:@"currencyFmt" , I get a compiler warning saying that the object may not respond to this selector. Everything works fine at runtime if I just ignore this warning, but the warnings are terrible and I don't want to comment on them there.
I tried declaring the property with @dynamic and @synthesize at the top of the file and nothing helps. What do I need to do to use the recommended dynamic accessors without generating these warnings?
Any help is greatly appreciated.
glenc source share