OC MRC之 @property参数(代码分析)
第一部分
//
// main.m
// 04-@property参数
//
// Created by apple on 13-8-9.
// Copyright (c) 2013年 itcast. All rights reserved.
//
#import <Foundation/Foundation.h> @interface Book : NSObject @end
#import "Book.h" @implementation Book @end #import <Foundation/Foundation.h>
#import "Book.h" @interface Person : NSObject
@property int age; // retain : 生成的set方法里面,release旧值,retain新值
@property (retain) Book *book;
@property (retain) NSString *name; @end #import "Person.h" @implementation Person //- (void)setBook:(Book *)book
//{
// if (_book != book)
// {
// [_book release];
//
// _book = [book retain];
// }
//} - (void)dealloc
{
[_book release];
[_name release];
[super dealloc];
} @end #import <Foundation/Foundation.h>
#import "Book.h" @interface Student : NSObject @property (retain) Book *book; @property (retain) NSString *name; @end #import "Student.h" @implementation Student - (void)dealloc
{
[_book release];
[_name release]; [super dealloc];
} @end #import <Foundation/Foundation.h>
#import "Person.h"
#import "Book.h" int main()
{
Book *b = [[Book alloc] init];
Person *p = [[Person alloc] init]; p.book = b; NSLog(@"%ld", [b retainCount]); [p release];
[b release];
return ;
}
第二部分
//
// main.m
// 05-@property参数
//
// Created by apple on 13-8-9.
// Copyright (c) 2013年 itcast. All rights reserved.
// #import <Foundation/Foundation.h> /*
1.set方法内存管理相关的参数
* retain : release旧值,retain新值(适用于OC对象类型)
* assign : 直接赋值(默认,适用于非OC对象类型)
* copy : release旧值,copy新值 2.是否要生成set方法
* readwrite : 同时生成setter和getter的声明、实现(默认)
* readonly : 只会生成getter的声明、实现 3.多线程管理
* nonatomic : 性能高 (一般就用这个)
* atomic : 性能低(默认) 4.setter和getter方法的名称
* setter : 决定了set方法的名称,一定要有个冒号 :
* getter : 决定了get方法的名称(一般用在BOOL类型)
*/ @interface Person : NSObject // 返回BOOL类型的方法名一般以is开头
@property (getter = isRich) BOOL rich; //
@property (nonatomic, assign, readwrite) int weight;
// setWeight:
// weight //
@property (readwrite, assign) int height; @property (nonatomic, assign) int age; @property (retain) NSString *name;
@end #import "Person.h" @implementation Person @end #import <Foundation/Foundation.h>
#import "Person.h" int main()
{
Person *p = [[Person alloc] init]; p.rich = YES; BOOL b = p.isRich; return ;
}
OC MRC之 @property参数(代码分析)的更多相关文章
- 七.OC基础加强--1.内存管理 2.野指针,内存泄露 3.set方法的内存管理 4.@property参数 5.@class和循环retain的使用 6.NSString的内存管理
1,内存管理简单介绍 1,为什么要有内存管理? malloc selloc dealloc```需要回头复习 一般的内存 4s 是512m内存:6 是1024m内存: 当内存过大时,会耗尽内存.出现程 ...
- JavaBean 基础概念、使用实例及代码分析
JavaBean 基础概念.使用实例及代码分析 JavaBean的概念 JavaBean是一种可重复使用的.且跨平台的软件组件. JavaBean可分为两种:一种是有用户界面的(有UI的):另一种是没 ...
- JQuery data API实现代码分析
JQuery data 接口是什么? .data() Store arbitrary data associated with the matched elements or return the v ...
- Device Tree(三):代码分析【转】
转自:http://www.wowotech.net/linux_kenrel/dt-code-analysis.html Device Tree(三):代码分析 作者:linuxer 发布于:201 ...
- Device Tree(三):代码分析
一.前言 Device Tree总共有三篇,分别是: 1.为何要引入Device Tree,这个机制是用来解决什么问题的?(请参考引入Device Tree的原因) 2.Device Tree的基础概 ...
- 【转】Device Tree(三):代码分析
原文网址:http://www.wowotech.net/linux_kenrel/dt-code-analysis.html 一.前言 Device Tree总共有三篇,分别是: 1.为何要引入De ...
- Linux内核启动代码分析二之开发板相关驱动程序加载分析
Linux内核启动代码分析二之开发板相关驱动程序加载分析 1 从linux开始启动的函数start_kernel开始分析,该函数位于linux-2.6.22/init/main.c start_ke ...
- tensorflow笔记:多层LSTM代码分析
tensorflow笔记:多层LSTM代码分析 标签(空格分隔): tensorflow笔记 tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) ten ...
- 1.ARC下是否有内存溢出等问题 2.@property参数 3.#import和@class的区别
1.ARC下是否有内存溢出等问题? 答案:必须要担心啊,ARC也不是万能的.答案:必须要担心啊,ARC也不是万能的.这里主要是涉及到集合类的数据类型 比如数组,我们定义了一个可变数组muarr1, ...
随机推荐
- P3868 [TJOI2009]猜数字
[TJOI2009]猜数字 中国剩余定理 求解i=1 to n : x≡a[i] (mod b[i])的同余方程组 设 t= ∏i=1 to n b[i] 我们先求出 i=1 to n : x≡1 ( ...
- 更改 Centos 6 的 yum 源
1.查看当前使用的源: yum repolist all 阿里源网址,使用方法点右边的帮助可以看到:https://opsx.alibaba.com/mirror 2.更改源: 第一步:备份你的原镜像 ...
- 《网络攻防》实验九:web安全基础实践
本次实验在XX同学的指导下完成 1.实验后回答问题 (1)SQL注入攻击原理,如何防御 SQL注入攻击的基本原理,是从客户端合法接口提交特殊的非法代码,让其注入到服务器端执行业务的SQL中去,进而改变 ...
- 《Python程序设计(第3版)》[美] 约翰·策勒(John Zelle) 第 1 章 答案
判断对错1.计算机科学是计算机的研究.2.CPU 是计算机的“大脑”.3.辅助存储器也称为 RAM.4.计算机当前正在处理的所有信息都存储在主存储器中.5.语言的语法是它的意思,语义是它的形式.6.函 ...
- Linux系统编程之--守护进程的创建和详解【转】
本文转载自:http://www.cnblogs.com/mickole/p/3188321.html 一,守护进程概述 Linux Daemon(守护进程)是运行在后台的一种特殊进程.它独立于控制终 ...
- VS中自动选择x86或x64的dll
http://www.cnblogs.com/lzjsky/archive/2010/09/06/1819321.html 原来使用Win7的32位系统,进行C#工程的开发,后来重装系统,换成了win ...
- Ubuntu 14.04 安装adobe flash player
参考: How to install flash payer in Ubuntu 14.04 LTS? [duplicate] Ubuntu 14.04 安装adobe flash player 32 ...
- LaTex: Undefined citation warnings 解决方法
参考 Undefined citations LaTex: Undefined citation warnings 解决方法 在使用TexMaker编译文献的时候,出现引用参考文献的问题: Packa ...
- hdu 1014 Uniform Generator 数论
摘取于http://blog.csdn.net/kenden23/article/details/37519883: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...
- Codeforces Beta Round #17 A.素数相关
A. Noldbach problem Nick is interested in prime numbers. Once he read about Goldbach problem. It sta ...