Get the address of an Objective-c property (which is a C struct)

前端 未结 4 449
南笙
南笙 2020-12-19 08:56

I have an Objective-C class which contains a C-style struct. I need to call a C function passing a pointer to this object member (a.k.a. property). For the life of me, I c

4条回答
  •  一生所求
    2020-12-19 09:56

    To get a pointer to the myStruct instance variable, you need to write a method that returns a pointer to that instance variable.

    - (void)getMyStructPointer:(MyStruct **)outStruct {
        *outstruct = &myStruct;
    }
    

    I don't really think this is a good idea, though. Other objects should not be mutating that object's ivar out from under it, and that's the only thing you can do with a pointer to the struct that you can't do with a copy of the struct returned by value.

提交回复
热议问题