【Objective-C学习-3】@property和@synthesize
来源:互联网 发布:look it over 编辑:程序博客网 时间:2024/05/20 16:11
#import <Foundation/Foundation.h>@interface Person : NSObject { //int _age;}//当编译器遇到@property时,会自动展开成getter和setter的声明@property int age;//- (int)age;//- (void)setAge:(int)newAge;- (void)test;@end
#import "Person.h"@implementation Person//@synthesize age; 默认会去访问跟age同名的变量//如果找不到同名的变量,会自动生成一个同名变量age//@synthesize age = _age; 表示getter和setter方法会去访问_age成员变量//如果.h文件没有声明_age,编译器会在.m文件中生成该私有成员变量//某个版本以上的XCode可以自动生成该语句//如果手动实现getter和setter方法,编译器不会自动生成该语句//如果手动实现getter或setter方法,编译器会自动生成该语句,相应的方法也会被覆盖@synthesize age = _age;//- (int)age {// return _age * 10;//}- (void)setAge:(int)newAge { _age = newAge * 10;}- (void)test { NSLog(@"I am %i years old.", _age);}@end
#import <Foundation/Foundation.h>#import "Person.h"int main(int argc, const char * argv[]) { @autoreleasepool { Person *person = [[Person alloc] init]; person.age = 380; NSLog(@"I am %i years old", person.age); [person test]; [person release]; //release直接释放 } return 0;}
0 0
- 【Objective-C学习-3】@property和@synthesize
- Objective-c @property和@Synthesize
- Objective-C学习——@property和@synthesize用法
- IOS学习之Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- objective-c之@synthesize和@property含义
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C中的@property和@synthesize用法
- Objective-C 之 @property和@synthesize
- Objective-C中的@property和@synthesize用法
- ios 在storyboary上布置uiwebview时出现的黑边
- zoj 1649 Rescue
- PHP算法大全
- 机器学习实战ByMatlab(一)KNN算法
- 02_java基础_数组、集合、枚举
- 【Objective-C学习-3】@property和@synthesize
- shell 脚本切换用户
- android developer tools下载地址
- 深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件
- PHP部分常见算法
- 机器学习实战ByMatlab(二)PCA算法
- Android学习系列(33)--App应用之提交到各大市场渠道
- linux 内核模块编程
- 查看Eclipse版本号及各个版本区别