【ARC与MRC的相互兼容 Objective-C语言】

前言

有可能以后在写项目的时候,会遇到这种情况:
1)你在ARC的模式下写项目,这时候,你需要使用1个别人写的类,但是这个类别人早就写好了,是MRC的。

一、例如,有1个Person类和1个Dog类,是你写的,是在ARC模式下,但是有一个Account类是别人写的,是在MRC机制下

#import <Foundation/Foundation.h>
#import “Dog.h”
@interface Person : NSObject
@property(nonatomic,strong)Nsstring *name;
@property(nonatomic,assign)int age;
@property(nonatomic,strong)Dog *dog;
@end

#import “Person.h”

@implementation Person

@end

#import <Foundation/Foundation.h>

@interface Dog : NSObject
@property(nonatomic,strong)Nsstring *color;
@property(nonatomic,assign)int age;
@end

#import “Dog.h”

@implementation Dog

@end

#import <Foundation/Foundation.h>

@interface Account : NSObject
@property(nonatomic,retain)Nsstring *userName;
@property(nonatomic,retain)Nsstrong *password;
@end

#import “Account.h”

@implementation Account

  • (void)dealloc
    {
    NSLog(@“账户被销毁了。。。”);
    [_userName release];
    [_password release];
    [super dealloc];
    }
    @end

二、遇到这种尴尬的情况:程序使用的是ARC机制开发的,但是其中的某些类,使用的是MRC。现在的需求是,编译器能不能让程序中的大部分类使用ARC,只有少部分的几个类使用MRC?

1.点击项目管理器最上面的项目,右边选中要修改的target,选择右边的Build Phases ,选择下面的Compile Sources(4 items),编译源,编译4个.m文件,那为什么不编译.h文件呢,因为.m文件里就包含了.h文件,现在这里有3个类,Account类,Person类,和Dog类,现在Account类使用MRC机制,不使用ARC,选中这个类,双击,弹出1个窗口出来,输入:-fno-objc-arc

2.使用命令:-fno-objc-arc

总结

指定某个类使用MRC,不使用ARC,就在这文件属性里,写上-fno-objc-arc即可

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...