黑马程序员--@synthesize的使用
来源:互联网 发布:导弹惯性制导难度知乎 编辑:程序博客网 时间:2024/06/05 07:03
------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
使用方法:
@synthesize方法名
注意:
方法名一定要先在 .h中使用 @property声明
Person.h文件
#import <Foundation/Foundation.h>@interface Person : NSObject{ NSString *_name; int _age;}//@property 编译器指令,帮我们进行_age _name get/set方法的声明@property int age;/*相当于 -(void)setAge:(int)age; -(int)age; */@property NSString *name;/*相当于 -(void)setName:(NSString *)name; -(NSString *)name;*/@end
Person.m文件
#import "Person.h"@implementation Person//@synthesize帮我们实现了 实例变量的get/set方法@synthesize name; //帮我们生成了一个变量 age/*相当于-(void)setName:(NSString *)name{ self->name = name;}-(NSString *)name{ return name;} */@synthesize age;/*相当于 -(void)setAge:(int)age{ self->age = age;}-(int)age{ return age;} */@end
main.m文件
#import <Foundation/Foundation.h>#import "Person.h"int main(int argc, const char * argv[]) { @autoreleasepool { Person *p = [Person new]; p.age = 20; p.name = @"刘禹锡"; NSLog(@"姓名:%@,年龄:%d",p.name,p.age); } return 0;}
0 0
- 黑马程序员--@synthesize的使用
- 黑马程序员-@property与@synthesize的用法
- 黑马程序员-----@property和@synthesize
- 黑马程序员---@property和@synthesize
- 黑马程序员 --- OC中@property和@synthesize的用法
- 07.黑马程序员-@property和@synthesize
- 黑马程序员_@property和@synthesize
- 黑马程序员------OC基础-----@property和@synthesize
- 黑马程序员---Objective-C @property和@synthesize
- 黑马程序员 oc随记 @proprety与@synthesize
- 黑马程序员——@property和@synthesize
- 黑马程序员-------OC----@property和@synthesize
- 黑马程序员——OC基础语法—@property和@synthesize使用
- 黑马程序员-OC语言-@synthesize关键字介绍和使用(听课笔记)
- 黑马程序员——OC语言基础---@synthesize关键字介绍和使用
- 黑马程序员——OC语言——@property和@synthesize使用
- iOS:@synthesize的使用
- 黑马程序员(OC特有的语法一@ property和synthesize)
- 第2周项目0宣告“主权”
- 程序员的数学2:概率统计——互动出版网
- 1.1 MFC对话框背景设置
- Linux access()函数 使用 http://blog.163.com/lqy_super/blog/static/199751021201302351831330/
- 第一周 项目0 宣告“主权”
- 黑马程序员--@synthesize的使用
- ora-01017 ora-02063 database link,oracle11.2g通过dblink连接oracle11.2g
- 第二周项目0 宣告“主权”
- sqlmap用户手册
- Eclipse网络求情返回数据多显示不全的处理
- KPCA降维
- Handler
- VPN技术概要
- 大学的多姿多彩。