Is it possible to define a class property in Objective-C?

To declare an instance property, you can use a declaration similar to this:

@property (readonly) int size;

The property can later be accessed using dotted syntax:

NSLog(@"The object has a size of: %d", objectInstance.size);

However, I would like to declare a class property so that even without an instance I could access it this way. For example:

NSLog(@"%d instances have been created.", ClassName.numberOfInstances);

I know that I could always implement this behavior with a class message and call it using the point syntax anyway, but I would prefer to have a declared property and benefit from the directive @synthesizefor some properties.

Is it possible?

+3
source share
1 answer

: , . . , , Apple - (, UIView), , KVC, .

, , , , , , .

+3

Source: https://habr.com/ru/post/1721220/


All Articles