On Jul 30, 2013, at 4:19 AM, Rick Mann <rm...@latencyzero.com> wrote:
> On Jul 30, 2013, at 00:59 , Vincent Habchi <vi...@macports.org> wrote:
> 
>> I have a very simple question: if I embed a C-function (more precisely, a 
>> callback from an external C-library) in an Obj-C object, can I expect this 
>> function to behave like a regular method? I.e. can it freely access ‘self’ 
>> and other attributes?
> 
> No; it'll be a stand-alone method with no implicit knowledge of the 
> Objective-C class.

This may be pedantic, but just to clarify: if you put a C function in MyClass's 
implementation file you aren't really "embedding" it in the sense that some 
people might think you mean.  There is no formal association between MyClass 
and the function, MyClass doesn't know about the function, and you can't call 
the function as if it were a method.  The function is not a method, stand-alone 
or otherwise.

The only effect, as others have explained, is on scope; if you put the function 
inside the @implementation and the function has a reference to an instance of 
MyClass, then it can use myObj->myIvar for direct access to instance variables.

The same is true for class methods, by the way.  If a class method has a 
reference to an instance of the class, it can directly access the instance's 
ivars the same way.

--Andy


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to