我的书籍范例程式码出现错误 [英] I have an Error with my books example code

查看:47
本文介绍了我的书籍范例程式码出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有本书教程中的这段代码:

I have this code from books tutorial:

 void drawShapes (id shapes[], int count)
 {
int i;

    for (i = 0; i < count; i++) {
id shape = shapes[i];
[shape draw];
 }

}

然后Xcode向我报告错误:自动引用计数问题:必须明确描述对象数组参数的预期所有权".

And Xcode reports me Error: "Automatic Reference Counting Issue: Must explicitly describe intended ownership of an object array parameter".

我在做什么错了?

推荐答案

此问题是由自动引用计数带来的.
ARC是由iOS5.0之后的Apple带来的.在默认的iOS项目中,选择了ARC.
使用ARC时,应该提到Array必须使用NSArray,或者必须告诉编译器该数组不是ARC对象.

This problem is brought by Automatic Reference Counting.
ARC is brought by Apple after iOS5.0. In default iOS project, ARC is selected.
When using ARC, you should mention that the Array must using NSArray, or you must tell the complier the array not an ARC object.

有两种方法可以解决此问题.两种方法都可以.

There are two methods to solve the problem. Two methods both work.

1.第一种方法就像以前发布的答案一样:

1.First Method like a previous posted answer:

void drawShapes (id __autoreleasing shapes[], int count)

告诉编译器不要在C类型的Array形状上使用ARC [].

tell the complier don't use ARC on this C type Array shapes[].


2.第二种方法,停止对项目使用ARC

Or
2.Second Method, stop using ARC to your project

如果该项目是iOS项目,则可以重新创建一个iOS项目,然后在对话框中取消选择自动引用计数".

If this project is iOS project, you can recreate a iOS project, then deselect the "Auto Reference Counting" in the dialog.

如果该项目是Mac OS Project(或者您不想创建新的iOS项目),请转到项目设置页面,然后选择建筑设置"标签,搜索自动引用计数",然后设置相对值为否".

If this project is Mac OS Project(or you don't want to create a new iOS project), go to the project setting page, then select "Building Settings" tag, search "Automatic Reference Counting", then set the relative value to "NO".

这篇关于我的书籍范例程式码出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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