A couple of suggestions.

> Here is what I have so far: I used a category on NSNumber to add a 
> "valueType" attribute as described at 
> http://nshipster.com/associated-objects/.
> 
> The formatter checks this and the user preference when formatting an incoming 
> value.  It sets some instance variables on itself to remember what it last 
> saw so that it can correctly default its interpretation of an entered value 
> when trying to send it back.
> 


On your associated object setter add KVO support.

- (void)setValueType:(int)valueType
{
    [self willChangeValueForKey:@"valueType"];
    objc_setAssociatedObject(self, @selector(valueType), @(valueType), 
OBJC_ASSOCIATION_RETAIN);
    [self didChangeValueForKey:@"valueType"];
}



> The binding for the values is indirect - to the effect of "myThing.value" - 
> and if I change "myThing" but the new thing has the same numeric value, the 
> formatter does not always seem to trigger to render the value in the correct 
> format - it holds that of the previous thing.  If I change the value from 
> another control, when the bindings update the field, the formatting is 
> suddenly corrected.

The formatter will only receiver the value part of “myThing.value”.
It may well be that the formatter doesn’t re-format because the actual value 
doesn’t change - formatting may be an expensive operation.
In this case you may want to reformat so:

1.  consider Manual triggering of reformat if valueType changes.
2. Try overriding NSFormatter -stringForObjectValue: - that should give you a 
low enough foothold into the rendering.

HTH

J


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to