Re: Elegant way to eliminate large conditional?
Re: Elegant way to eliminate large conditional?
- Subject: Re: Elegant way to eliminate large conditional?
- From: Nathan Day <email@hidden>
- Date: Tue, 7 Jan 2003 17:30:28 +1030
Create a property list file with keys as units and values equal to what
the units have to be multiplied by to convert them to degrees kelvin.
Then in your program create a NSDictionary with the property list file
and use the allKeys method to dynamically build you popup to and from
menus. Then convert by multiplying by the from units and dividing by
the to units. If you want to add more unit all you have to do is edit
the property list file.
On Tuesday, January 7, 2003, at 07:11 AM, Jeff Szuhay wrote:
I'm developing a program that includes a unit converter which, among
other things, can convert from any one of five temperature scales to
any of the other five temperature scales. The code is hard to
maintain, unfortunately, as I use a rather long conditional (with
multiple sub-conditionals) to determine the "to" and "from" scales.
Is there some (elegant) way to use a matrix-like setup (a
two-dimensional selector or even an array?) that, given two arguments
(a range of five numbers, for each of the temperature scales) will
execute a different one of 25 equations or selectors?
Nathan Day
http://homepage.mac.com/nathan_day/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.