使用Xcode 5禁用ARC [英] Disable ARC with Xcode 5

查看:135
本文介绍了使用Xcode 5禁用ARC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在5之前的Xcode版本中,我们可以在创建项目时在项目设置中禁用ARC.现在,ARC为我造成了这个问题.

In versions of Xcode previous to 5, we can disable ARC in the project settings when we create the project. Now ARC is causing this problem for me.

对于一个属性列表文件,在读取步骤中,编译器给我一个错误:"ARC不允许将'int'隐式转换为'id'".我在使用Xcode 4的相同代码时没有这个问题.在我的属性列表文件中,键是数字,在viewController.m中.当我禁止目标使用ARC时,警告仍然存在.

With an property list file, for the reading step, the compiler gives me an error: "implicit conversion of 'int' to 'id' is disallowed with ARC". I did not have this problem with the same code with Xcode 4. In my property list file, The keys are numbers and also in my viewController.m When I disallow ARC for the target, the warning persists.

我看不到如何添加编译器标志.代码(带有法语字符串):

I don't see how I can add a compiler flag. The code (with French strings):

NSString *error;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];


NSString *plistPath = [rootPath stringByAppendingPathComponent:@"Save.plist"];

NSArray *keys = [NSArray arrayWithObjects:@"valeurCompteur1", @"valeurCompteur2", @"valeurCompteur3", @"valeurCompteur4", @"valeurCompteur5", @"nomCompteur1", @"nomCompteur2", @"nomCompteur3", @"nomCompteur4", @"nomCompteur5", nil];

NSArray *objs = [NSArray arrayWithObjects: compteur1, compteur2, compteur3, compteur4, compteur5, nameC1, nameC2, nameC3, nameC4, nameC5, nil];

推荐答案

如果要手动引用计数(使用保留和发布),可以在构建设置中禁用ARC.

If you want manual reference counting (using retains and releases) you can disable ARC in the build settings.

在项目导航器中选择项目.编辑器区域应显示一个带有四个选项卡的视图:信息,构建设置,构建阶段,构建规则.选择构建设置.

Select the project in the project navigator. The editor area should show you a view with four tabs: info, build settings, build phases, build rules. Select build settings.

这四个标题的左侧,应该有一个下拉列表,用于选择所需的目标.选择您不需要ARC的目标.

To the left of those four titles, there should be a drop down list for selecting the target you want. Select the target you don't want ARC for.

向下滚动以找到标题为"Apple LLVM 5.0-语言-Objective-C"的部分.下有三个设置.最底下的应该是"Objective-C自动引用计数".将其设置为否",您将拥有手动引用计数.

Scroll down to find the section titled "Apple LLVM 5.0 - Language - Objective-C". Under there are three settings. The bottom one should be "Objective-C Automatic Reference Counting". Set that to "No" and you will have manual reference counting.

但是,解决所报告的问题可能是一个更好的选择.最好使用ARC.

It might be a better option, however, to fix the reported problem. It's better to use ARC than not.

要纠正错误

您说您的错误发生在创建obis数组的行上.这意味着以下一个或多个变量是int而不是对象:

You say your error occurred on the line where you create the obis array. This means that one or more of the following variables is an int instead of an object:

compteur1, compteur2, compteur3, compteur4, compteur5, nameC1, nameC2, nameC3, nameC4, nameC5

如果要将整数放入数组中,则必须将其装箱为NSNumber例如

If you want to put an integer into an array, you have to box it as an NSNumber e.g.

NSArray* anArray = [NSArray arrayWithObjects: [NSNumber numberWithInt: 2], nil];

现在有一种简写形式,看起来像这样:

There is a shorthand form of writing that now, which looks like this:

NSArray* anArray =  @[ @(2) ];

这篇关于使用Xcode 5禁用ARC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆