您的位置:首页 > 移动开发 > Objective-C

objective-c系列-@Property&点语法

2015-11-12 19:16 453 查看
//解释 property后边的圆括号中的修饰词的含义:

// nonatomic 非线程安全 非原子操作 特点是: 操作变量的效率高

// atomic 线程安全 原子操作 特点是: 操作变量的效率低

//

// retain 强引用实例变量, 即 setter方法中会有:

// -(void)setXXX:(xxx)arg

// {

// [_属性名 release];

// _属性名 = [arg retain];

// }

// 而且该类需要重写 dealloc方法

// 非oc字符串的其它所有类对象都要用retain

//

// copy 复制, 即setter方法中会有:

// -(void)setXXX:(xxx)arg

// {

// [_属性名 release];

// _属性名 = [arg copy];

// }

// 而且该类需要重写 dealloc方法

// copy适用的对象为: oc字符串, block

//

// assign 直接赋值, 即setter方法中会有:

// -(void)setXXX:(xxx)arg

// {

// _属性名 = arg;

// }

// 适用于所有非对象的数据类型:int float, char, struct

// union, void *, SEL, CLASS BOOL 枚举

// readonly 不对外提供setter方法, 限定实例变量不能被外部修改

************************************************

// 点语法

@class Person;

Person *person = [[Person alloc] init];

person.name = @"海燕";// setter方法

NSString *love = person.name; // getter方法

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: