Do I need ARC keywords for properties that I don't synthesize?

对着背影说爱祢 提交于 2019-12-03 15:50:31

The declared attributes that you are referencing are optional. To quote the documentation:

Property Declaration and Implementation
The @property directive declares a property. An optional parenthesized set of attributes provides additional details about the storage semantics and other behaviors of the property - see “Property Declaration Attributes” for possible values.

Property Declaration Attributes
You can decorate a property with attributes by using the form @property(attribute [, attribute2, ...]). Like methods, properties are scoped to their enclosing interface declaration. For property declarations that use a comma-delimited list of variable names, the property attributes apply to all of the named properties.

If you use the @synthesize directive to tell the compiler to create the accessor methods (see “Property Implementation Directives”), the code it generates matches the specification given by the keywords. If you implement the accessor methods yourself, you should ensure that it matches the specification (for example, if you specify copy you must make sure that you do copy the input value in the setter method).

If you then use @dynamic instead of @synthesize it is telling the compiler that you will be writing your own methods and prevents it from complaining when it doesn't find suitable methods.

More information can be found here.

borrrden,

First, why do you care to elide your memory policy in your property statement? It announces to consumers of your class what the policy is. Don't you want them to know?

Second, the @synthesize is not a nop. It is the mechanism by which the language support KVO. While you may not be using that now, why would you preclude this use for the future.

Frankly, by not using a full description in @property nor using @synthesize, you are, IMO, engaging in premature optimization. Your current design doesn't save you message dispatches and forces you to manage, if necessary, the creation and typing of ivars. And you are losing features of the language.

Unless you have a good reason to get outside the bounds of the preferred Obj-C v2+ patterns, and you haven't listed those, then I would return to using the standard pattern. Then your problem just goes away.

Andrew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!