我倾向于按以下顺序声明我的属性属性:写入性,设置器语义,原子
例如:
@property (readwrite, strong, nonatomic) NSString *foo;
我只是想知道Objective-C开发人员中是否有普遍接受的惯例?苹果的文档似乎对此保持沉默。
no。
您将看到代码,甚至从Apple中看到,它们以不同的订单声明。这对编译器没有任何影响,并且由于没有大量的编译器,因此并不一定会使代码更容易阅读。
使用您喜欢的任何惯例(包括无关)。
以下是叮当声对应的源代码。XCode可以根据枚举顺序生成代码。因此,我认为没有此属性的确切约定令。
/// Represents one property declaration in an Objective-C interface.
///
/// For example:
/// code{.mm}
/// @property (assign, readwrite) int MyProperty;
/// endcode
class ObjCPropertyDecl : public NamedDecl {
public:
enum PropertyAttributeKind {
OBJC_PR_noattr = 0x00,
OBJC_PR_readonly = 0x01,
OBJC_PR_getter = 0x02,
OBJC_PR_assign = 0x04,
OBJC_PR_readwrite = 0x08,
OBJC_PR_retain = 0x10,
OBJC_PR_copy = 0x20,
OBJC_PR_nonatomic = 0x40,
OBJC_PR_setter = 0x80,
OBJC_PR_atomic = 0x100,
OBJC_PR_weak = 0x200,
OBJC_PR_strong = 0x400,
OBJC_PR_unsafe_unretained = 0x800,
/// Indicates that the nullability of the type was spelled with a
/// property attribute rather than a type qualifier.
OBJC_PR_nullability = 0x1000,
OBJC_PR_null_resettable = 0x2000,
OBJC_PR_class = 0x4000
// Adding a property should change NumPropertyAttrsBits
};
enum {
/// Number of bits fitting all the property attributes.
NumPropertyAttrsBits = 15
};
/* Omitted */
};