您的位置:首页 > 编程语言

20150619_OC之ARC与MRC混合编程

2015-07-03 09:07 225 查看
//
//  main.m
//  IOS_ObjectiveC_ARC_MRC混合编程
//
//  Created by Peng Junlong on 15/6/19.
//  Copyright (c) 2015年 Peng Junlong. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"
#import "Dog.h"

//************************
//*     ARC_MRC混合编程    *
//************************

//Dog和person类是之前的MRC编译的(MRC是手动管理内存,我们在使用第三方库的时候,有时很多都是MRC编译的文件,在编译出错时可以使用一下方法)
//MRC -->Manual Reference Counting
//ARC -->Automatic Reference Counting
//一般将MRC编译的文件导入到ARC环境中运行的时候,需将MRC的文件编译器标志改一下,
//在Build Phases->Compile Sources->Compiler Flag中添加"-fno-objc-arc",添加时没有双引号
//将ARC放在MRC环境中时添加-fobjc-arc
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *person = [[Person alloc] init];
Dog *dog = [[Dog alloc] init];
person.dog = dog;
}
return 0;
}


//
//  Dog.h
//  IOS150618_ObjectiveC复合类的内存管理_下
//
//  Created by Peng Junlong on 15/6/18.
//  Copyright (c) 2015年 Peng Junlong. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Dog : NSObject
@property (copy,nonatomic)NSString *name;
@property (assign,nonatomic)NSInteger age;
@end


//
//  Dog.m
//  IOS150618_ObjectiveC复合类的内存管理_下
//
//  Created by Peng Junlong on 15/6/18.
//  Copyright (c) 2015年 Peng Junlong. All rights reserved.
//

#import "Dog.h"

@implementation Dog

- (void)dealloc
{
NSLog(@"Dog is release:%@",[self class]);
[_name release];
[super dealloc];
}
@end


//  Person.h
//  IOS150618_ObjectiveC复合类的内存管理_下
//
//  Created by Peng Junlong on 15/6/18.
//  Copyright (c) 2015年 Peng Junlong. All rights reserved.
//

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

@interface Person : NSObject
@property (retain,nonatomic)Dog *dog;
@end


//  Person.m
//  IOS150618_ObjectiveC复合类的内存管理_下
//
//  Created by Peng Junlong on 15/6/18.
//  Copyright (c) 2015年 Peng Junlong. All rights reserved.
//

#import "Person.h"

@implementation Person
- (void)dealloc
{
NSLog(@"Person is release :%@",[self class]);
[_dog release];
[super dealloc];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: