第六天-ARC中@property

//
//  main.m
//  09-ARC中@property
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CZPerson.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
     
        
        CZPerson * person = [[CZPerson alloc] init];
        CZDog *dog = [[CZDog alloc] init];
        
        //      把狗给人
        person.dog = dog;
        //      把人给狗
        dog.person = person;
        
    }
    return 0;
}


//
//  CZPerson.h
//  1201-内存管理
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CZDog.h"
/*
 内存管理
    strong   对于普通对象
    copy     字符串
   assign    基本数据类型
   weak      循环引用一端必须使用weak
 
 
 */

@interface CZPerson : NSObject


//年龄
@property (nonatomic,assign) int age;
//姓名
@property (nonatomic,copy) NSString * name;
//狗
@property (nonatomic,strong) CZDog * dog;


@end

//
//  CZPerson.m
//  1201-内存管理
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "CZPerson.h"

@implementation CZPerson


-(void)dealloc
{
    //  验证对象是否被销毁了
    NSLog(@"%s",__func__);
    //    [super dealloc];
}

@end

//
//  CZDog.h
//  1201-内存管理
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import <Foundation/Foundation.h>

@class CZPerson;

@interface CZDog : NSObject
//当出现循环引用的时候,必须保证一端是weak的
@property (weak,nonatomic) CZPerson *person;

@end

//
//  CZDog.m
//  1201-内存管理
//
//  Created by Apple on 14/12/1.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#import "CZDog.h"

@implementation CZDog

-(void)dealloc
{
    //  验证对象是否被销毁了
    NSLog(@"%s",__func__);
    //    [super dealloc];
}
@end


你可能感兴趣的:(第六天-ARC中@property)