On 26 Oct 2013, at 21:28, jonat...@mugginsoft.com wrote: > On 25 Oct 2013, at 10:58, jonat...@mugginsoft.com wrote: > >> Value transformers applied to NSPopupButton have some idiosyncrasies. >> http://stackoverflow.com/questions/12505764/nspopupbutton-bindings-with-value-transformer >> >> I have applied a transformer to an NSPopupButton content values binding but >> the IB configured transformer does not seem to be applied. >> I am not alone in this: http://macscripter.net/viewtopic.php?id=39496 >> >> If I log the binding the transformer is present. >> However, if I enter an invalid transformer name the app does not raise >> (which it should). >> If I then log the binding with the invalid name then it does raise. >> > The initial scenario was: > > 1. NSPopUpButton Content bound to arrayController.arrangedObjects > 2. NSPopUpButton Content values bound to arrayController.arrangedObjects.name > 3. A value transformer that returns NSString applied to the Content values > binding. > > This initial scenario does indeed ignore the value transformer. > This one is a conversation with myself. However:
My adopted workaround to this is: 1. Remove the non functional transformer from the content values binding. 2. Define a category method on the objects returned by arrayController.arrangedObjects: @implementation MyObject (MyCat) - (NSString *)transName { return [self extValueForKey:@"name" withTransformerForName:@"MyTransformer"]; } @end 3. Define the value for key transformer extension method: @implementation NSObject (MyCat) - (id)extValueForKey:(NSString *)key withTransformerForName:(NSString *)transformerName { return [[NSValueTransformer valueTransformerForName:transformerName] transformedValue:[self valueForKey:key]]; } @end 4. NSPopUpButton Content values bound to arrayController.arrangedObjects.transName This work around is compatible with the Content Objects and Selected Object bindings. The approach is acceptable I feel for custom classes where a category method has limited scope. I wouldn't want to utilise it in the case say of an NSDictionary binding. Jonathan _______________________________________________ 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