4.2OC8-@property和synthesize
例一:
-------------main.m-----------------
//
// main.m
// 构造方法
//
// Created by liuyes on 13-12-8.
// Copyright (c) 2013年 renhe. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Student *stu = [[Student alloc] init];
stu.age = 29;
int age = stu.age;
NSLog(@"age is %i", age);
[stu release];
}
return 0;
}
-------------Student.h-----------------
// Student.h
// 构造方法
//
// Created by liuyes on 13-12-8.
// Copyright (c) 2013年 renhe. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Student : NSObject{
//默认是@protected
int age;
int no;
float height;
}
//当编译器遇到@property时,会自动展开成getter和setter的声明
//- (void)setAge:(int)age;
//- (int)age;
@propertyint age;
@propertyint no;
@propertyfloat height;
@end
-------------Student.m-----------------
//
// Student.m
// Copyright (c) 2013年 renhe. All rights reserved.
//
#import "Student.h"
@implementation Student
@synthesize age;
@synthesize no;
@synthesize height;
@end
例二:
-------------main.m-----------------
//
// main.m
// 构造方法
//
// Created by liuyes on 13-12-8.
// Copyright (c) 2013年 renhe. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Student *stu = [[Student alloc] init];
stu.age = 29;
int age = stu.age;
NSLog(@"age is %i", age);
[stu release];
}
return 0;
}
-------------Student.h-----------------
// Student.h
// 构造方法
//
// Created by liuyes on 13-12-8.
// Copyright (c) 2013年 renhe. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Student : NSObject{
//默认是@protected
int _age;
int _no;
float _height;
}
//当编译器遇到@property时,会自动展开成getter和setter的声明
//- (void)setAge:(int)age;
//- (int)age;
@propertyint age;
@propertyint no;
@propertyfloat height;
@end
-------------Student.m-----------------
//
// Student.m
// Copyright (c) 2013年 renhe. All rights reserved.
//
#import "Student.h"
@implementation Student
@synthesize age = _age;
@synthesize no = _no;
@synthesize height = _height;
@end
例三:
-------------main.m-----------------
-------------Student.h-----------------
-------------Student.m-----------------
相关推荐
相信每个初学者对@property和@synthesize都感到非常的陌生,在此给大家分享下我的自己的理解,有不当之处,还望多多指教。详细说明文章在下面连接http://blog.csdn.net/comeontom/article/details/7455459
针对iOS开发中属性 property 和 synthesize 进行了详细介绍
@property (nonatomic, retain) NSMutableString *currentResult; @property (nonatomic, retain) NSMutableDictionary *map; @property (nonatomic, retain) NSMutableArray *list; -(NSMutableDictionary *)...
资源分类:Python库 所属语言:Python 资源全名:synthesize-0.0.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
3D-Synthesize3DviaDepthOrSil.zip,[CVPR 2017]通过建模多视图深度图或轮廓生成和重建三维形状,3D建模使用专门的软件来创建物理对象的数字模型。它是3D计算机图形的一个方面,用于视频游戏,3D打印和VR,以及其他...
1. 使用@property和@synthesize声明一个成员变量,给其赋值是时要在前面加上"self.",以便调用成员变量的setmember方法。 直接调用成员变量并且给其赋值:member=[NSString stringWithFormat:@””];将不执行...
本套PPT,拥有以下OC语言的内容: ...二、OC的特有语法(点语法、@property、@synthesize关键字、id、构造方法、分类、description、SEL) 三、内存管理 四、协议(protocol)代码块(block) 五、ARC 等等
Synthesize Synthesize is an android library which can create layout images in background threads, services, etc without inflating them in activity or fragments. Synthesize Documentation
[xmlString appendString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"]; [self getNodeStr:self string:xmlString]; return xmlString; } -(void)getNodeStr:(XmlNode *)node string:(NSMutableString *)str...
*/@property ( nonatomic , copy ) NDHandler handler;- ( void ) handle ;@end对ObjC ++爱好者的支持// For ObjC++using namespace Neodata::VaridictHandler;@implementation Consumer@synthesize handler = _...
自动创建简单的方法来获取和设置 JavaScript 模块的属性,类似于 iOS Objective-C 中的 @synthesize 指令。 用法 在这个例子中,我们在 MyClass 原型上创建了一个名为 name() 的 getter/setter 方法: var MyClass...
@property (nonatomic, retain) NSArray *changeArray; @property (nonatomic, retain) NSMutableString *changeString; @property (nonatomic, retain) UILabel *codeLabel; -(void)changeCode; @end .m文件 @...
Electrochemical and Spectroscopic Behaviour of Bis(2-mercaptopyridine-N-oxide)oxovanadium(IV) Electrochemical and Spectroscopic Behaviour of ...captopyridine N-oxide) was synthesize
Synthesize & Power Analyze
8. Missing in this release 9. New in version 4.x 10. TODO 11. Licence, Copyright and Disclaimer 12. Release history ------------------------------------------- 1. Supported platforms: --------------...
Electrochemical and Spectroscopic Behaviour of Bis(2-mercaptopyridine-N-oxide)oxovanadium(IV) Electrochemical and Spectroscopic Behaviour of ...captopyridine N-oxide) was synthesize
应该做的第一件事就是预先加载RCTBridge并将其引用保存在某个地方(可能是AppDelegate ): AppDelegate.h @property (nonatomic, strong) RCTBridge *bridge; AppDelegate.m @synthesize bridge;...- ( BOOL )...
ObjcAssociatedObjectHelpers 介绍 在OS X 10.6和iOS 4.0中引入了。 此功能为类实例提供了各种字典,可以使用运行时函数objc_setAssociatedObject()和objc_getAssociatedObject()在... SYNTHESIZE_ASC_OBJ(myCategoryOb
Code to synthesize Arithmetic Logic Unit