On 30/11/2009, at 7:44 AM, Jericho Hasselbush wrote: > I've been considering the best way to integrate user's choice of units in my > app (metric and standard) and have yet to figure out a clean way of doing it. > > I am considering using a custom formatter that will change it's behavior > based on a globally accessible variable holding the type of system - probably > in the App Delegate, since the app will store the data in the same units no > matter what. The respective controllers can watch the keyValue of the app > delegate and update their respective views when the App Delegate's variable > changes. > > Is this an acceptable use of a custom formatter, or am I making this harder > than necessary?
I did something similar recently, using a custom NSFormatter subclass. There was nothing very unusual about the subclass, except I needed two things: a) a way to change between metric/imperial for all fields in my app at once, and b) ensure that when I did, the associated control actually got updated. To do that, I used separate instances of the formatter, but each one automatically added itself (and removed itself when necessary) to a global list that was easily iterated when the setting changed. Class methods accessed this global list giving a direct way to change all instances in use. Each instance also had a weak ref to its control so it could update it when the change occurred. I could set up the formatter in IB as usual. The formatter itself didn't need very much work, because the standard formatter accepts properties such as a multiplication factor and a suffix string, so you can set those to apply the conversion and to append 'cm', 'in' or whatever. --Graham _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
