0
我想知道如何将指向struct的指针传递给nsoperation的自定义init方法。它似乎期望通过一个ID类型的项目。如何将结构传递给NSOperation Init
这可能吗?
typedef struct mystruct
{
int a;
int b;
}mystruct;
mystruct myitem;
MyNSOperation *op=[[MyNSOperation alloc]initwithdata:myitem]; //can't do this, not of type id
-(id)initwithdata:(mystruct *)thestruct
{
}
我似乎无法定义 - (id)initwithdata:(mystruct)在NSOperation子类标题中的结构。我得到一个编译器错误,说“预计(在mystruct之前” – dubbeat
尝试通过引用,然后MyNSOperation * op = [[MyNSOperation alloc] initwithdata:&myitem];' – Nekto
@dubbeat - 您可以移动结构的定义到你的NSOperation子类还是一些共享的头文件?你肯定可以使用一个自定义结构作为初始化的参数,但是编译器需要知道它是什么。 –