开发者

What are the constraints on Cocoa Framework version numbers?

We're distributing a Cocoa framework with regular updates. We'll be updating the version numbers with each release. The Apple documentation appears to suggest that version numbers should be consecutive incrementing integers. We are distributing output in several formats, and the framework is only one o开发者_StackOverflow中文版f them. We would rather not have to maintain a separate numbering system just for our frameworks.

We don't really care about the precise format of the version numbers of the framework, so long as they change whenever the product changes, and behave in a correct, sensible and expected manner. I'm looking for a way of avoiding having to run a separate version number counter.

One suggestion is that for product version 12.34.56 we could simply remove the dots and say the framework version is 123456 (with appropriate zero padding).

  • Is there a constraint on the type of number that can be represented (uint? long?)
  • Does it have to be a number? Could it be a string?
  • Do the numbers have to be consecutive?
  • Is there a standard way of doing things in this situation?


As I understand it, the reason for this requirement is so that you can have macro checks like:

#if FRAMEWORKNAME_VERSION >= 123456
    // some stuff
#else
    // some other stuff
#endif

The numbers do not need to be consecutive, and your suggested scheme is quite sensible:

#define MAKE_VERSION(MAJOR,MINOR,PATCH) ((MAJOR*10000)+(MINOR*100)+PATCH)

I would also suggest that in addition to defining a version, you also define constants for each version...

#define FRAMEWORKNAME_VERSION_1_0_0 MAKE_VERSION(1,0,0)
#define FRAMEWORKNAME_VERSION_1_0_1 MAKE_VERSION(1,0,1)

That way, you can check in multiple ways... either:

#if FRAMEWORKNAME_VERSION >= MAKE_VERSION(1,0,1)
    // 1.0.1 and later
#else
    // Before 1.0.1
#endif

Or:

#if defined(FRAMEWORKNAME_VERSION_1_0_1)
    // 1.0.1 and later
#else
    // Before 1.0.1
#endif

The key requirements that you should satisfy are:

  • The numbers are monotonically increasing
  • The numbers are predictable
  • The numbers are easily comparable

If you want to supply a string representation of your version in addition to the integer representation, by all means go ahead; however, I would strongly suggest that you have an integer representation available, as it simplifies comparison and allows the version to be checked in the preprocessor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜