"必须明确描述对象数组参数的预期所有权"是什么意思,我该如何解决?

ite*_*nyh 3 iphone objective-c

以下函数定义的第一行有问题:

void draw(id shapes[], int count)
{   
    for(int i = 0;i < count;i++) {
        id shape = shapes[i];
        [shape draw];
    }
}   
Run Code Online (Sandbox Code Playgroud)

编译失败,并显示错误"必须显式描述对象数组参数的预期所有权".

错误的确切原因是什么?我该如何解决?

das*_*ght 7

您正在ARC环境中传递一组指针.您需要指定以下之一:

  • __强大
  • __弱
  • __unsafe_unretained
  • __autoreleasing

我认为在你的情况下__unsafe_unretained应该工作,假设你没有对你draw()同时传递的形状做任何事情.

void draw(__unsafe_unretained id shapes[], int count)
{
    for(int i = 0;i < count;i++) {
        id shape = shapes[i];
        [shape draw];
    }
}
Run Code Online (Sandbox Code Playgroud)