`
zhiblin
  • 浏览: 57753 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
社区版块
存档分类
最新评论

关于retain 、readonly、readwrite、copy、assign的详细介绍

阅读更多

iphone开发一定会遇到

@property (retain, nonatomic) IBOutlet UITextView *descText;

其中的retain 还可以填写为其他如readonly、retain、read write、copy、assign等属性。

具体代表的意思下面列出:

retain   When you’re dealing with object values. The compiler will retain the value you pass in (we’ll talk more about retaining in a minute) and release the old value when a new one comes in.

 

readonly   When you don’t want people modifying the property.You can still change the field value backing the

property, but the compiler won’t generate a setter.

 

readwrite   When you want the property to be modifiable by people. The compiler will generate a getter and a  setter for you. This is the default.

 

copy             When you want to hold onto a copy of some value instead of the value itself; for example, if you want to hold onto an array and don’t want people to be able to change its contents after they set it. This sends a copy message to the value passed in then retains that.

 

assign       When you’re dealing with basic types, like ints, floats, etc. The compiler just creates a setter with a simple myField = value statement. This is the default, but not usually what you want.

 

分享到:
评论

相关推荐

    iOS开发之详谈属性设置readwrite、readonly、retain、copy、assign、nonatomic

    本篇文章详细介绍了iOS开发中的一些常见属性设置,包括readwrite、readonly、retain、copy、assign以及nonatomic。 1. 可读性: - `readwrite`:这是变量的默认属性,如果没有明确指定其他属性,变量就会具有读写...

    ios_assign,retain和copy详解

    关于属性声明,需要补充的知识点还包括readonly和readwrite属性。readonly表示属性是只读的,只能通过getter方法访问。readwrite表示属性是可读写的,既可以通过getter也可以通过setter方法访问。 此外,内存管理...

    Ios retain assign区别

    本文将详细解释`retain`和`assign`的区别,以及其他相关的属性修饰符如`readonly`、`readwrite`、`nonatomic`等,帮助读者更好地理解这些关键字的作用及其应用场景。 #### `retain`与`assign` **1. `retain`** - *...

    OC中的@property属性问题

    在OC中,我们可以为属性指定不同的属性修饰符,如`retain`、`copy`、`assign`等,以及`readwrite`、`readonly`和`atomic`、`nonatomic`。下面将详细介绍这些修饰符的意义和用法。 ### `assign` `assign`是最简单的...

    iOS 对象属性详细介绍

    retain,strong, copy,weak,assign,readonly, readwrite, unsafe_unretained 下面来分别讲讲各自的作用和区别: retain,计数器加1, (增加一个指向内存的指针) 对应release(计数器-1) setter 方法对参数进行 ...

    Objective-c 学习 (2).doc

    1. **读写属性(readwrite/readonly)**: - `readwrite`:默认值,会自动生成getter和setter方法,属性可读可写。 - `readonly`:只生成getter方法,没有setter方法,意味着属性是只读的。 2. **setter语意...

    iOS笔试题011

    iOS 中的属性可以分为六种:readwrite、readonly、assign、retain、copy、nonatomic。每种属性都有其特定的作用和使用场景: * readwrite:同时生成 get 方法和 set 方法的声明和实现。 * readonly:只生成 get ...

    阿里p4-p6面试题.pdf

    - 文档中提到了几种属性关键字:readwrite, readonly, assign, retain, copy, nonatomic。 - readwrite和readonly用于指定属性是否可读写,readwrite可以读写,而readonly只能读。 - assign通常用于基本数据类型...

    iOS常见面试题

    #### 三、属性 `readwrite`,`readonly`,`assign`,`retain`,`copy`,`nonatomic` 各是什么作用,在那种情况下用? - **`readwrite`**: - 默认属性,表示同时生成get方法和set方法。 - 适用于需要可读写属性的...

    IOS开发之@property的详细介绍

    - **readwrite/readonly**:读写权限,`readwrite`表示既有setter又有getter,`readonly`只有getter没有setter。默认是`readwrite`。 - **assign/reteain/copy**:内存管理策略。`assign`适用于非对象类型,不改变...

    IOS property属性详细介绍使用注意事项

    以下是对标题“IOS property属性详细介绍使用注意事项”所涉及知识点的详细说明: 1. **原子性 (Atomicity)** - **atomic**:原子性是指在多线程环境下,编译器会为getter和setter方法添加同步锁,以防止同一时刻...

    ios就业面试题.docx编程资料

    - **`readwrite`/`readonly`**:`readwrite`表示属性既有setter也有getter方法,允许外部修改该属性的值;`readonly`表示只有getter方法,不允许外部修改该属性的值。 - **`assign`**:用于基本数据类型如`int`、`...

    objective-c资料

    - `readwrite`:默认的,表示既有setter又有getter。 - `readonly`:只提供getter,没有setter,属性是只读的。 点表达式是Objective-C中的另一个重要概念,如`对象.变量`。这种语法使得我们可以像访问成员变量一样...

    ios 面试题

    - **readwrite、readonly:** - `readwrite`:默认属性,表示属性既可以通过getter获取也可以通过setter修改。 - `readonly`:只允许通过getter获取属性值,不允许通过setter修改。 - **nonatomic、atomic:** - ...

    iOS最新面试题及答案(7.29)

    `readwrite`提供读写访问,适用于需要getter和setter的情况;`readonly`只提供getter,不生成setter;`assign`用于非对象属性,不保留引用计数;`retain`和`copy`用于对象属性,`retain`增加对象的引用计数,`copy`...

    8.1《iOS开发笔试题600道-笔试手写篇》(2).pdf

    属性可以包含不同的特性,比如readwrite(读写)、readonly(只读)、nonatomic(非原子的)、atomic(原子的)、strong(强引用)、weak(弱引用)、assign(直接赋值)、copy(复制)等。 在iOS开发中,正确使用@...

Global site tag (gtag.js) - Google Analytics