Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c @property声明属性的顺序是否有公认的约定?_Objective C_Properties - Fatal编程技术网

Objective c @property声明属性的顺序是否有公认的约定?

Objective c @property声明属性的顺序是否有公认的约定?,objective-c,properties,Objective C,Properties,我倾向于按以下顺序声明属性:可写性、Setter语义、原子性 例如: @property (readwrite, strong, nonatomic) NSString *foo; 我只是想知道Objective-C开发人员之间是否有一个普遍接受的约定?似乎对此保持沉默。没有 您将看到代码,甚至是来自苹果的代码,它们以不同的顺序声明。它对编译器没有任何影响,而且由于没有太多的编译器,因此也不一定使代码更易于阅读 使用您喜欢的任何约定(不包括约定)。下面是对应的源代码。Xcode可以根据枚举顺序

我倾向于按以下顺序声明属性:可写性、Setter语义、原子性

例如:

@property (readwrite, strong, nonatomic) NSString *foo;
我只是想知道Objective-C开发人员之间是否有一个普遍接受的约定?似乎对此保持沉默。

没有

您将看到代码,甚至是来自苹果的代码,它们以不同的顺序声明。它对编译器没有任何影响,而且由于没有太多的编译器,因此也不一定使代码更易于阅读


使用您喜欢的任何约定(不包括约定)。

下面是对应的源代码。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 */
};