Class objects behave like regular objects. They can be stored, released, passed as arguments and return values, stored in ivars and properties, stored in containers - basically anything.
[SomeClassName class] usually not compiled or linked if such a class cannot be found, but it can be compiled, but return zero, for example, when working in an OS that does not have this class, ie An older OS version than the development SDK version. The return value of NSClassFromString will be nil if such a class does not exist.
The value of the pointer (identifier) ββof class objects never changes. There is only one class object for each class name, and you can use the C == operator to check if the class pointers are the same. (The subclass / superclass relation can be checked using the class method + isSubclassOfClass: .
Class objects are never freed - you can rely on them to be alive (i.e. without saving them) until the process completes completely.
The above is true for most applications; however, there is a complex case of beam loading (and an even more complicated case of beam unloading):
- A boot package can add classes at runtime, for example. calling
NSClassFromString to start returning non-nil for its names. - If dynamic package loading causes class name collisions, the runtime currently logs a complaint but continues to work; it is not indicated what exactly happens in this case.
- With Mac OS X 10.5, you can download a package that causes its classes to be deleted. It is not indicated what should happen if some of these classes were saved.
source share