首页 > 其他 > 详细

Objective-C - @property参数

时间:2015-04-21 09:37:07      阅读:191      评论:0      收藏:0      [点我收藏+]

@property参数

/*
 1.set方法内存管理相关的参数
 * retain : release旧值,retain新值(适用于OC对象类型)
 * assign : 直接赋值(默认,适用于非OC对象类型)
 * copy   : release旧值,copy新值

 2.是否要生成set方法
 * readwrite : 同时生成setter和getter的声明、实现(默认)
 * readonly  : 只会生成getter的声明、实现

 3.多线程管理
 * nonatomic : 性能高 (一般就用这个)
 * atomic    : 性能低(默认)

 4.setter和getter方法的名称
 * setter : 决定了set方法的名称,一定要有个冒号 :
 * getter : 决定了get方法的名称(一般用在BOOL类型)
 */

@interface Person : NSObject


// 返回BOOL类型的方法名一般以is开头
@property (getter = isRich) BOOL rich;

//   
@property (nonatomic, assign, readwrite) int weight;
// setWeight:
// weight

// 
@property (readwrite, assign) int height;

@property (nonatomic, assign) int age;

@property (retain) NSString *name;
@end
@implementation Person

@end

Book类

@interface Book : NSObject

@end
@implementation Book

@end

Student类

#import "Book.h"

@interface Student : NSObject

@property (retain) Book *book;

@property (retain) NSString *name;

@end
@implementation Student


- (void)dealloc
{
    [_book release];
    [_name release];

    [super dealloc];
}

@end
int main()
{
    Book *b = [[Book alloc] init];
    Person *p = [[Person alloc] init];

    p.book = b;


    NSLog(@"%ld", [b retainCount]);


    [p release];
    [b release];
    return 0;
}

Objective-C - @property参数

原文:http://blog.csdn.net/wangzi11322/article/details/45165863

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!