在结构中使用 Objective-C 对象时修复 ARC 错误 [英] Fixing ARC error when using Objective-C object in struct

查看:32
本文介绍了在结构中使用 Objective-C 对象时修复 ARC 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Xcode 项目有问题.

I am having an issue with my Xcode project.

我有这些行:

typedef struct
{
    NSString *escapeSequence;
    unichar uchar;
}

我收到此错误:

ARC 禁止在结构体或联合体中使用 Objective-C 对象.

ARC forbids Objective-C objects in structs or unions.

我该如何解决?

我似乎无法找到这如何违反 ARC,但我很想学习.

I cannot seem to find how this violates ARC but I would love to learn.

推荐答案

改为:

typedef struct
{
    __unsafe_unretained NSString *escapeSequence;
    unichar uchar;
}MyStruct;

但是,我建议遵循 本文档中的 Apple 规则.

ARC 执行新规则

不能在 C 结构中使用对象指针.
您可以创建一个 Objective-C 类来管理数据,而不是使用结构体.

You cannot use object pointers in C structures.
Rather than using a struct, you can create an Objective-C class to manage the data instead.

这篇关于在结构中使用 Objective-C 对象时修复 ARC 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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