Re: Newbie: compare version string
Re: Newbie: compare version string
- Subject: Re: Newbie: compare version string
- From: Fritz Anderson <email@hidden>
- Date: Sun, 9 Dec 2007 09:10:48 -0600
On 9 Dec 2007, at 8:43 AM, norio wrote:
Is there APIs which compare two version strings: like 10.5 is less
than 10.5.1 or 10.5 is greater than 10.4.11.
Is it OK to use NSString's compare method? Or should I split those
strings by period and make scalers from them?
To my knowledge, there is no such API. My practice is to split by '.'
and compare components. If you're parsing general version strings, be
aware that some application version numbers have _four_ components,
even for released products. (The theory being apparently that you need
to enumerate bug-fix versions of a bug-fix version.) Also, many
version strings involve build numbers (some of which are not numeric
-- e.g. 9B18).
Finally, if you find what we used to call an Apple-style version --
1.2b9 -- you have to sort by (v/r/null) > b > a > d.
A lexical comparison (-[NSString compare:]) won't work, even without
fourth versions and stage letters. Consider that 10.4.1 < 10.4.11 <
10.4.2.
See also the thread(s) from a month or two ago about obtaining and
comparing system version numbers. It was quasi-religious, and I'm sure
I haven't assimilated all of it.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden