iOS 项目运行“ARC forbids Objective-C objects in struct”错误

iOS 项目运行“ARC forbids Objective-C objects in struct”错误

前言:
项目加入了一个MRC的库,然后运行项目,提示“ARC forbids Objective-C objects in struct”错误,这边我也参考了一些文章。这边先把我自己的代码和解决方法给贴出来。

一、解决问题
有一个MRC的 .h文件的typedef中,用到了OC对象,代码如下:

typedef struct structBlueTooth
{
    NSString *nsBlueToothName;
    NSString *nsBlueToothDevId;
}STRUCE_BLUETOOTH;

typedef struct binderstructBlueTooth
{
    NSMutableArray *nsArrayBlueToothName;
    NSMutableArray *nsArrayBlueToothDevId;
}BINDER_STRUCE_BLUETOOTH;
查阅资料,得知:
在`ARC`环境下,在结构体中使用`objc`对象,必须使用  `__unsafe_unretained`,这个是苹果的规定。

解决后代码:

typedef struct structBlueTooth
{
    __unsafe_unretained NSString *nsBlueToothName;
    __unsafe_unretained NSString *nsBlueToothDevId;
}STRUCE_BLUETOOTH;

typedef struct binderstructBlueTooth
{
    __unsafe_unretained NSMutableArray *nsArrayBlueToothName;
    __unsafe_unretained NSMutableArray *nsArrayBlueToothDevId;
}BINDER_STRUCE_BLUETOOTH;

参考链接:
参考文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值