OC property(声明)
@interface Student : NSObject {
int _age;
int _no;
float _height;
}
// 当编译器遇到@property时,会自动展开成getter和setter的声明
@property int age;
//- (void)setAge:(int)newAge;
//- (int)age;
@property int no;
//- (void)setNo:(int)newNo;
//- (int)no;
@property float height;
//- (void)setHeight:(float)newHeight;
//- (float)height;
- (void)test;
@end
// 在xcode4.5的环境下,可以省略@synthesize,并且默认会去访问_age这个成员变量
// 如果找不到_age这个成员变量,会自动生成一个叫做_age的私有成员变量
@implementation Student // @synthesize age, height, no; // @synthesize会自动生成getter和setter的实现 // @synthesize默认会去访问跟age同名的变量
// 如果找不到同名的变量,会自动生成一个私有的同名变量age
// @synthesize age; // age = _age代表getter和setter会去访问_age这个成员变量
@synthesize age = _age;
//- (void)setAge:(int)newAge {
// _age = newAge;
//}
//
//- (int)age {
// return _age;
//} @synthesize height = _height;
//- (void)setHeight:(float)newHeight {
// _height = newHeight;
//}
//
//- (float)height {
// return _height;
//} @synthesize no = _no;
//- (void)setNo:(int)newNo {
// _no = newNo;
//}
//
//- (int)no {
// return _no;
//} - (void)test { _age = ; _height = 10.0f; _no = ; }
@end
OC property(声明)的更多相关文章
- 01 (OC)* @property 后面可以有哪些修饰符?
一:@property 后面可以有哪些修饰符? 1:线程安全的: atomic,nonatomic 2:访问权限的 readonly,readwrite 3:内存管理(ARC) assign, cop ...
- 用@property声明的NSString(或NSArray,NSDictionary)经常使用copy关键字,为什么?如果改用strong关键字,可能造成什么问题?
因为父类指针可以指向子类对象,使用 copy 的目的是为了让本对象的属性不受外界影响,使用 copy 无论给我传入是一个可变对象还是不可对象,我本身持有的就是一个不可变的副本. 如果我们使用是 str ...
- OC @property @synthesize和id
文顶顶 OC语言@property @synthesize和id OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字 ...
- OC @protocol(声明协议 )
@protocol Study; int main(int argc, const char * argv[]) { @autoreleasepool { Student *stu = [[[Stud ...
- 【IOS】3. OC 类声明和实现
.h文件 @interface NewClassName:ParentClassName { 实例变量://基本类型和指针类型 不能在这里初始化,系统默认会初始化 系统初始化遵循: 实例变量类型 ...
- [OC] @property时,copy、strong、weak、assign的区别
@property(copy,nonatomic)NSMutableString*copyStr; @property(strong,nonatomic)NSMutableString*strongS ...
- OC block声明和使用
#import "Button.h" typedef int (^MySum) (int, int); void test() { // 定义了一个block,这个block返回值 ...
- oc @property参数
- OC 方法声明使用
Person.h #import <Foundation/Foundation.h> @interface Person : NSObject { int _age; } - (void) ...
随机推荐
- B. Divisors of Two Integers
B. Divisors of Two Integers time limit per test 1 second memory limit per test 256 megabytes input s ...
- phantomjs的和谷歌浏览器的简单使用
一.phantomjs的简单使用 ''' 什么是phantomJs:无界面的浏览器 ''' from selenium import webdriver from time import sleep ...
- PyCharm常见用法
1.设置python运行版本: File-->Setting-->Project-->Project Interpreter 2.代码批量左移/右移一个tab: 鼠标选中行,Tab右 ...
- cloudera manager的7180 web界面访问不了的解决办法(图文详解)
说在前面的话 我的机器是总共4台,分别为ubuntucmbigdata1.ubuntucmbigdata2.ubuntucmbigdata3和ubuntucmbigdata4.(注意啦,以下是针对Ub ...
- 牛客网Java刷题知识点之OSI七层参考模型 和 TCP/IP五层参考模型
不多说,直接上干货! 福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号: 大数据躺过的坑 Java从入门到架构师 人工智能躺过的坑 ...
- Unity3D 发布成PC端常用设置
本文,基于Unity 5.6pro版本来发布PC端.文中若有不妥之处,欢迎各位指出! 一.如何去掉Unity官方水印? 首先,你需要pro版本的Unity3D.如果,你是personal版本的话,就需 ...
- Linux Kernel文件系统写I/O流程代码分析(一)
Linux Kernel文件系统写I/O流程代码分析(一) 在Linux VFS机制简析(二)这篇博客上介绍了struct address_space_operations里底层文件系统需要实现的操作 ...
- JavaScript对象 创建对象(一)
创建对象 --以下内容来自JavaScript高级程序设计 工厂模式 用函数来封装以特定接口创建对象的细节. function createPerson(name, age, job){ var o ...
- SQL 表定时同步
1.创建存储过程 create proc [dbo].[sync_calendar] as truncate table dbo.CalendarEvents insert into Calendar ...
- Cannot execute request on any known server
1.com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: c ...