2

When I look at the header NSObject.h for Objective-C, I find some code like the following but I can't find out the meaning of class as an attribute of property.

@protocol NSSecureCoding <NSCoding>
@required
// This property must return YES on all classes that allow secure coding. Subclasses of classes that adopt NSSecureCoding and override initWithCoder: must also override this method and return YES.
// The Secure Coding Guide should be consulted when writing methods that decode data.
@property (class, readonly) BOOL supportsSecureCoding;
@end

What does the class attribute mean?

Bill David
  • 95
  • 5

1 Answers1

1

The class attribute is used to declare a class property. A class property is shared by all instances of the class, unlike an instance property where each instance has its own copy. Class properties where introduced in Xcode 8 and unlike instance properties they are never synthesised and the programmer must write the getter and setter.

See this question and answer for more details.

CRD
  • 52,522
  • 5
  • 70
  • 86