Accessing Instance Variable in C Style Method

后端 未结 3 1932
北恋
北恋 2021-01-19 13:07

Can someone confirm that you cannot access instance variables defined in an Objective C @implementation block from within C style functions of the same class? The compiler

3条回答
  •  天命终不由人
    2021-01-19 13:45

    A "C style method" doesn't really deserve the name "method", I'd call it a "function" instead as in C.

    A C function has no self, so it cannot implicitly access ivars as a method can. If you pass an instance to the C function as a parameter, you can access ivars in the same manner you would access a field in a struct pointer.

提交回复
热议问题