iphone - iVars, With and Without self? -


i curious role self plays within object. understand writing [[self datafortable] count] refers directly ivar contained in object. if miss self off , directly specify ivar [datatable count] how differ, protecting against using self, uniquely specify ivar rather maybe similar local variable?

@implementation viewcontroller @synthesize datafortable;  ...  nsuinteger datacount = [[self datafortable] count]; 

much appreciated

gary.

writing [[self datafortable] count] does not refer directly ivar. there's behind-the-scenes stuff going on...

if use ivar in code without self, that's direct access ivar. if use either [self someivarname] or self.someivarname, you're sending message object (which self). runtime attempts resolve message , use 1 of number of mechanisms: if have defined method matching name, method used, if no such method (or property) exists, key-value-coding use identically named ivar default.

as impact, differ based on code. example if property retained property (as opposed assigned), there's significant difference between:

somevar = nil 

and

self.somevar = nil 

the synthesized setter release somevar before setting nil, whereas in first example, you've leaked memory. 1 example of difference.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -