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;
参考链接:
参考文章