Re: Obtaining version number of framework at runtime... API available?
Re: Obtaining version number of framework at runtime... API available?
- Subject: Re: Obtaining version number of framework at runtime... API available?
- From: "Erik M. Buck" <email@hidden>
- Date: Mon, 12 Nov 2001 21:51:42 -0600
See version
+ (int)version
Returns the version number assigned to the class. If no version has been
set, the default is 0.
Version numbers are needed for decoding or unarchiving, so older versions of
an object can be detected and decoded correctly.
Caution should be taken when obtaining the version from within NSCoding
protocol or other methods. Use the class name explicitly when getting a
class version number:
version = [MyClass version];
Don't simply send version to the return value of class-a subclass version
number may be returned instead.
See Also: + setVersion: - versionForClassName: (NSCoder)
Pay special attention to -versionForClassName:
I usually implement plugins/loadable components with a single class or
protocol to encapsulate whatever other classes and complexity may be
contained in the plugin/loadable component. Each time the component changes
in an incompatible way, I change the version of the principalClass via
+setVersion in +initialize. When loading the plugin/component I
use -versionForClassName:
Of course, the real art is to not break component compatibility from version
to version.
Note: the component can also check the loading application's version to
prevent loading a version 5 component into a version 3 application that may
not support all required interfaces.
There is also -conformsToProtocol: which can be used very flexibly. A
loading application can check that the plugin conforms to any required
protocol and visa versa. That is more flexible than a version number. Each
time a significant change is made to the plugin or application, create a new
protocol that includes the prior protocol for backward compatibility.