`
chenniaoc
  • 浏览: 39898 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Declared Properties

阅读更多
Writability

These attributes specify whether or not a property has an associated set accessor. They are mutually exclusive.

readwrite

    Indicates that the property should be treated as read/write. This is the default.

    Both a getter and setter method will be required in the @implementation. If you use @synthesize in the implementation block, the getter and setter methods are synthesized.
readonly

    Indicates that the property is read-only.

    If you specify readonly, only a getter method is required in the @implementation. If you use @synthesize in the implementation block, only the getter method is synthesized. Moreover, if you attempt to assign a value using the dot syntax, you get a compiler error.

Setter Semantics

These attributes specify the semantics of a set accessor. They are mutually exclusive.

assign

    Specifies that the setter uses simple assignment. This is the default.

    You typically use this attribute for scalar types such as NSInteger and CGRect, or (in a reference-counted environment) for objects you don’t own such as delegates.

    retain and assign are effectively the same in a garbage-collected environment.
retain

    Specifies that retain should be invoked on the object upon assignment. (The default is assign.)

    The previous value is sent a release message.

    Prior to Mac OS X v10.6, this attribute is valid only for Objective-C object types (so you cannot specify retain for Core Foundation objects—see “Core Foundation”).

    On Mac OS X v10.6 and later, you can use the __attribute__ keyword to specify that a Core Foundation property should be treated like an Objective-C object for memory management, as illustrated in this example:

    @property(retain) __attribute__((NSObject)) CFDictionaryRef myDictionary;

copy

    Specifies that a copy of the object should be used for assignment. (The default is assign.)

    The previous value is sent a release message.

    The copy is made by invoking the copy method. This attribute is valid only for object types, which must implement the NSCopying protocol. For further discussion, see “Copy.”

Different constraints apply depending on whether or not you use garbage collection:

    *

      If you do not use garbage collection, for object properties you must explicitly specify one of assign, retain or copy—otherwise you will get a compiler warning. (This encourages you to think about what memory management behavior you want and type it explicitly.)

      To decide which you should choose, you need to understand Cocoa’s memory management policy (see Memory Management Programming Guide).
    *

      If you use garbage collection, you don't get a warning if you use the default (that is, if you don’t specify any of assign, retain or copy) unless the property's type is a class that conforms to NSCopying. The default is usually what you want; if the property type can be copied, however, to preserve encapsulation you often want to make a private copy of the object.
分享到:
评论

相关推荐

    ObjCRuntimeGuide

    - **Declared Properties:** Objective-C supports properties, which provide a convenient way to access instance variables. The document covers the type and functions associated with properties, ...

    objective c英文原版

    5. 属性(Declared Properties):属性提供了一种声明接口中变量的方式,并且提供了getter和setter方法。文档会介绍属性声明、属性声明属性、属性实现指令、使用属性、支持的类型、属性重声明、Core Foundation、...

    Objective-c官方文档 批注版

    4. 属性(Declared Properties) - 阐述了属性的声明和实现,属性声明的属性、属性声明的属性、以及属性实现的指令。 - 说明了如何使用属性、支持的类型以及属性的重声明。 - 涉及了与Core Foundation的子类化、...

    DevExpress VCL 13.2.5 D7-DXE6 FullSource

    •B254896 - dxZoomTrackBar - The "List capacity out of bounds" error occurs when setting Properties.Min/Properties.Max greater/less than 100 •Q468799 - In-place cxRichEdit - The width taken into ...

    IOS5 Programming Cookbook

    - **Property Declaration**: Properties are declared in the class interface using the `@property` keyword. For example, `@property (nonatomic, strong) NSString *name;`. - **Synthesizing Properties**: ...

    EHLib 6.3.171〖D7~XE5〗

    Use the procedure GridDefaultDrawStyleEh, SetGridDefaultDrawStyleEh, declared in a module GridsEh.pas to access GridDrawStyle the object. TGridDrawStyleEh type has the following properties: ...

    C# - CSharp 12 in a Nutshell The Definitive Reference

    One of the core features of C# is its type safety, which ensures that variables can only hold values of the types they were declared to hold. This helps prevent runtime errors and makes the code more ...

    C++_CLI标准.pdf

    - **Declared Accessibility**: Section 10.6.1 discusses declared accessibility of members. - **Name Lookup**: Section 10.7 covers name lookup rules in C++/CLI. #### Preprocessor (Chapter 11) - **...

    geoserver_OpenLayers_安装配置2.0.2

    确保"Declared SRS"选择正确,比如这里选择了"2010"。"Native Bounding Box"和"Lat/Lon Bounding Box"可以通过计算来自数据自动填充。 完成这些配置后,你可以在"Layers"列表中看到新添加的图层。点击"Layer ...

    SCJP6 Sun Certificated Programmer for Java 6 Study Guide (Exam 310-065) 英文原版

    - **Inheritance**: How to create a hierarchy of classes by inheriting properties and behaviors from a superclass. - **Polymorphism**: Using interfaces and abstract classes to achieve polymorphism. - *...

    PHP中static关键字以及与self关键字的区别

    Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property declared as static cannot be accessed with an instantiated cla

    Cours-VB-NET-2010-Developpez-com

    For example, a car can be considered an object with properties (color, make, model) and behaviors (drive, stop). ##### 2. In Visual Basic .NET In VB.NET, objects are used extensively. They are the ...

    JSP Simple Examples

    Custom Exception inherits the properties from the Exception class. Whenever we have declare our own exceptions then we call it custom exceptions. Throwing an exception All methods use the throw ...

    Programming dynamic ALV in WebDynpro for ABAP

    这可以通过在组件控制器 (`COMPONENT_CONTROLLER`) 和视图属性 (`View Properties`) 标签页中按下相应按钮完成。 #### ![图片示例] 此时,我们已经拥有一个 ALV 组件及其对应的控制器。 #### ![图片示例] ##### ...

    LambdaProbe 中文包下载

    <br>Declared datasources <br> <br>Application deployment 发布应用 <br> <br>Log file browser 日志文件浏览器 <br> <br>System information 系统信息 <br> <br>Connector ...

    sqlalchemy

    ### SQLAlchemy:对象关系映射(ORM)详解 #### 概述 SQLAlchemy 是一个 Python 的 SQL 工具包和 ORM(对象关系映射),它提供了一种方式将自定义的 Python 类与数据库表关联起来,并将这些类的实例(对象)与其...

    王小平版遗传算法的光盘源代码

    Here is how the properties of a function are assigned in make_function_table(pop_struct *pop): pop[0].function_table[0].arity = 2; pop[0].function_table[0].macro = FALSE; pop[0].function_...

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    Chapter 5Nested Classes and Interfacesdescribes how classes and interfaces can be declared inside other classes and interfaces, and the benefits that provides. Finally, Chapter 6Enumeration ...

Global site tag (gtag.js) - Google Analytics