Object-C 学习笔记(四 )@property 属性标志的使用
来源:互联网 发布:python json api接口 编辑:程序博客网 时间:2024/04/29 22:28
@property的使用方法:
声明property的语法为:@property (参数1,参数2) 类型 名字;
1、在头文件中:
@property int count;
等效于在头文件中声明2个方法:
- (int)count;
-(void)setCount:(int)newCount;
2、实现文件(.m)中
@synthesize count;
等效于在实现文件(.m)中实现2个方法。
- (int)count
{
return count;
}
-(void)setCount:(int)newCount
{
count = newCount;
}
以上等效的函数部分由编译器自动帮开发者填充完成,简化了编码输入工作量。
百度百科上讲的很好:http://baike.baidu.com/view/5028218.htm
@property (参数1,参数2) 类型 名字 中的参数的相关解释,请参考:http://blog.csdn.net/wudidalishi/article/details/8275525
自己写的例子:
Person。h
#import <Foundation/Foundation.h>@interface Person : NSObject@property(readwrite,assign) NSString *name;@property(readwrite,assign) int age;@end
Person。m
#import "Person.h"@implementation Person@synthesize name;@synthesize age;@end
main.h
#import <Foundation/Foundation.h>#import "Person.h"int main(int argc, const char * argv[]){ @autoreleasepool { Person *person=[[Person alloc] init]; person.age =12; person.name=@"杨过"; NSLog(@"姓名: %@, 年龄: %i ",person.name,person.age); } return 0;}
- Object-C 学习笔记(四 )@property 属性标志的使用
- object-c学习笔记:属性变量(property)
- object-c @property 的使用
- object-c @property 的使用
- object-c @property 的使用
- object-c 学习笔记四
- Objective-C 学习笔记 11 - 属性Property
- object-c学习:@property 属性中 assign,nonatomic,retain,strong,weak的区别
- object-c学习:@property 属性中 assign,nonatomic,retain,strong,weak的区别
- (object-c)属性的使用
- Object-C学习笔记四-----组合
- ios object-c中property(属性)的作用和类别分析
- Object-C 学习笔记(五)-----NSMutableDictionary的使用
- IOS-1-Objective-C-@property属性的使用及注意问题:@property(assign)int name;
- Object-c @property的使用方法
- Object-c @property的使用方法
- Object-c------@property的参数
- [Object-C]_[初级]_[object类的对象和属性@property]
- MIT-BIH心电数据库的使用
- Windows系统文件夹全面大揭密
- 看过这么多大牛之类的话 一些摘录 分享给大家
- Oracle练习(一)
- C语言中的typeof关键字
- Object-C 学习笔记(四 )@property 属性标志的使用
- oracle练习(二)
- oracle练习(三)
- Windows蓝屏(错误代码说明一览表)
- 一分钟搞清内核加载模块
- win7豪华功能(不用XP是对的)
- 现在开始要看的书
- java基础的学习
- swftools 命令