//
// 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修饰符的更多相关文章

  1. @property修饰符

    @property修饰符 修饰是否生成getter方法的 readonly 只生成setter方法,不生成getter方法 readwrite 既生成getter 又生成setter方法(默认) @p ...

  2. @property详解,@property修饰符以及各个修饰符区别(上)

    相信很多参加过面试的人员很多都会被问到:weak与assign的区别,copy与strong的区别.如果你仅仅说一点点copy一般对NSString,weak对于控件的修饰,assign对于基本类型, ...

  3. 张超超OC基础回顾_05 property修饰符,id类型,instancetype。。。

    一.property 如果给一个属性同时提供了getter/setter方法, 那么我们称这个属性为可读可写属性 如果只提供了getter方法, 那么我们称这个属性为只读属性 如果只提供了setter ...

  4. @property 修饰符

    原子性--- nonatomic 特质 在默认情况下,由编译器合成的方法会通过锁定机制确保其原子性(atomicity).如果属性具备 nonatomic 特质,则不使用同步锁.请注意,尽管没有名为“ ...

  5. @property的4类修饰符

    一.读写性修饰符:readwrite | readonly readwrite:表明这个属性是可读可写的,系统为我们创建这个属性的setter和getter方法. readonly:表明这个属性只能读 ...

  6. staticmethod classmethod修饰符

    一.staticmethod(function) Return a static method for function.A static method does not receive an imp ...

  7. 01 (OC)* @property 后面可以有哪些修饰符?

    一:@property 后面可以有哪些修饰符? 1:线程安全的: atomic,nonatomic 2:访问权限的 readonly,readwrite 3:内存管理(ARC) assign, cop ...

  8. iOS 属性修饰符记录 --不定时更新

    重新审视了一下OC在属性修饰符,特意记录一下来.以后不定时更新 > retain:只有在非ARC下才会有效,所有如果在ARC下使用了retain修饰也白搭 如以下的data属性用retain修饰 ...

  9. iOS之属性修饰符 retain、strong和copy区别测试

    时不时会有点迷惑属性修饰符retain.strong.copy三者之间的区别,还是把测试过程记录下来好一点! 1.属性修饰符结论 2.给retain.strong.copy修饰的字符串属性赋值指针变化 ...

随机推荐

  1. CF126B Password

    思路: kmp略作修改. 实现: #include <iostream> #include <cstdio> using namespace std; ; int neXt[M ...

  2. 一篇文章告诉你如何使用EF CodeFirst做增删改查

    一.修改数据 其实修改涉及的内容挺多的,是相对于其他操作来说比较繁琐.也是本文的重头戏. 虽然都是基础内容,但是也是值得细细品味的. 1.最简单直接的修改数据就是从数据库里检索出数据修改相应的字段即可 ...

  3. 白盒-CNN纹理深度可视化: 使用MIT Place 场景预训练模型

    MIT发文:深度视觉的量化表示................ Places2 是一个场景图像数据集,包含 1千万张 图片,400多个不同类型的场景环境,可用于以场景和环境为应用内容的视觉认知任务. ...

  4. HDU_4826_dp

    Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. What is the difference between Gradle Build and Gradle Sync?

    Gradle Build helps you to compile your Android app into an APK while Gradle Sync will sync up all yo ...

  6. 基于python xlsxwriter、xlrd 生成测试报告

    import xlsxwriter,xlrd ''' 思路: 1.获取数据 2.整合数据 3.写入文件 ''' #筛选 def filt(category,table,filt_name=None,r ...

  7. 前端自动化构建工具gulp使用

    1. 全局安装 gulp: $ npm install --global gulp 2. 作为项目的开发依赖(devDependencies)安装: $ npm install --save-dev ...

  8. Linux之iptables(二、基本认识和组成)

    iptables的基本认识 Netfilter组件 内核空间,集成在linux内核中 扩展各种网络服务的结构化底层框架 内核中选取五个位置放了五个hook(勾子) function(INPUT.OUT ...

  9. Linux - docker基础

    目录 Linux - docker基础 docker的概念 docker安装流程 docker基本命令学习 docker 的 hello docker 运行一个ubuntu容器 Docker与Cent ...

  10. 1、深度学习模型的基本结构——RNN

    本系列为深度学习课程笔记,课程网址在http://speech.ee.ntu.edu.tw/~tlkagk/courses_MLDS17.html 深度学习的基本步骤:定义模型-->定义损失函数 ...