oc29--property修饰符
//
// Person.h #import <Foundation/Foundation.h> @interface Person : NSObject /*
如果给一个属性同时提供了getter/setter方法, 那么我们称这个属性为可读可写属性
如果只提供了getter方法, 那么我们称这个属性为只读属性
如果只提供了setter方法, 那么我们称这个属性为只写属性
如果既没有提供getter也没有提供setter方法, 那么我们称这个属性为私有属性 格式:
@property(属性修饰符) 数据类型 变量名称;
*/
// readwrite: 代表既生成getter方法 , 也生成setter方法
// 默认情况下 @property就是readwrite的
@property(readwrite) int age;
/*
- (void)setHeight:(double)height;
- (double)height; - (void)setHeight:(double)height;
- (double)abc;
*/
@property(getter=abc) double height; /*
- (void)setWeight:(double)weight;
- (void)tiZhong:(double)weight;
*/
@property(setter=tiZhong:) double weight; // readonly: 代表只生成getter方法不生成setter方法,只有get方法没有set方法, [p setName:@"lnj"]就报错。需要自己写一个set方法。
@property(readonly) NSString * name; // 是否已婚
// 程序员之间有一个约定, 一般情况下获取BOOL类型的属性的值, 我们都会将获取的方法名称改为isXXX
@property(getter=isMarried) BOOL married;
@end
//
// Person.m #import "Person.h" @implementation Person @end
// main.m
// property修饰符 #import <Foundation/Foundation.h>
#import "Person.h" int main(int argc, const char * argv[]) { Person *p = [Person new];
// p.age = 30;
// p.name = @"猪立叶";
// p.height = 1.88;
// p.weight = 200.0;
[p setName:@"lnj"];
p.height = ;
NSLog(@"height = %f", [p abc]); [p tiZhong:100.0];
NSLog(@"weight = %f", [p weight]); [p setMarried:YES];
/*
if ([p married]) {
NSLog(@"已婚");
}else
{
NSLog(@"未婚");
}
*/ if ([p isMarried]) {
NSLog(@"已婚");
}else
{
NSLog(@"未婚");
}
return ;
}
oc29--property修饰符的更多相关文章
- @property修饰符
@property修饰符 修饰是否生成getter方法的 readonly 只生成setter方法,不生成getter方法 readwrite 既生成getter 又生成setter方法(默认) @p ...
- @property详解,@property修饰符以及各个修饰符区别(上)
相信很多参加过面试的人员很多都会被问到:weak与assign的区别,copy与strong的区别.如果你仅仅说一点点copy一般对NSString,weak对于控件的修饰,assign对于基本类型, ...
- 张超超OC基础回顾_05 property修饰符,id类型,instancetype。。。
一.property 如果给一个属性同时提供了getter/setter方法, 那么我们称这个属性为可读可写属性 如果只提供了getter方法, 那么我们称这个属性为只读属性 如果只提供了setter ...
- @property 修饰符
原子性--- nonatomic 特质 在默认情况下,由编译器合成的方法会通过锁定机制确保其原子性(atomicity).如果属性具备 nonatomic 特质,则不使用同步锁.请注意,尽管没有名为“ ...
- @property的4类修饰符
一.读写性修饰符:readwrite | readonly readwrite:表明这个属性是可读可写的,系统为我们创建这个属性的setter和getter方法. readonly:表明这个属性只能读 ...
- staticmethod classmethod修饰符
一.staticmethod(function) Return a static method for function.A static method does not receive an imp ...
- 01 (OC)* @property 后面可以有哪些修饰符?
一:@property 后面可以有哪些修饰符? 1:线程安全的: atomic,nonatomic 2:访问权限的 readonly,readwrite 3:内存管理(ARC) assign, cop ...
- iOS 属性修饰符记录 --不定时更新
重新审视了一下OC在属性修饰符,特意记录一下来.以后不定时更新 > retain:只有在非ARC下才会有效,所有如果在ARC下使用了retain修饰也白搭 如以下的data属性用retain修饰 ...
- iOS之属性修饰符 retain、strong和copy区别测试
时不时会有点迷惑属性修饰符retain.strong.copy三者之间的区别,还是把测试过程记录下来好一点! 1.属性修饰符结论 2.给retain.strong.copy修饰的字符串属性赋值指针变化 ...
随机推荐
- Android studio & SDK的国内有效站点。
SDK.TOOLS的国内有效镜像节点: mirrors.zzu.edu.cn/android/repository/ 网上的地址只写了mirrors.zzu.edu.cn,有误,需要补齐后面的子目录才 ...
- PAT甲级1016Phone Bills
#include<iostream> #include<cstdio> #include<cstdlib> #include<vector> #incl ...
- JS——对象创建
1.原始创建 <script> person = new Object();//不要var person.firstname = "Bill"; person.last ...
- Java_Web三大框架之Hibernate增删改查
下面介绍一下Hibernate的增删改查. 第一步:编写用户实体类以及User.hbm.xml映射 package com.msl.entity; public class User { privat ...
- 【sqli-labs】 less60 GET -Challenge -Double Query -5 queries allowed -Variation3 (GET型 挑战 双查询 只允许5次查询 变化3)
http://192.168.136.128/sqli-labs-master/Less-60/?id=1")%23 http://192.168.136.128/sqli-labs-mas ...
- js的replace, 高亮
";console.log(str.replace(/\,/g, "")); //输出 123 ";console.log(str);//输出123 " ...
- CAD从二制流数据中加载图形(com接口)
主要用到函数说明: _DMxDrawX::ReadBinStream 从二制流数据中加载图形,详细说明如下: 参数 说明 VARIANT varBinArray 二制流数据,是个byte数组 BSTR ...
- iview表单密码自定义验证
From中定义 ref="passwordForm" 获取dom节点 :model="passwordForm" 关联表单数据对象 :rules=&quo ...
- C++实现双人枪战游戏
//单机版枪战游戏,喜欢就拿走,把赞留下//by floatiy #include<iostream> #include<cstdio> #include<windows ...
- 00.pip安装包
pip安装更换镜像源 pip install 包名 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com pip导出和导入 ...