Where are synthesized ivars stored?

I read on automatically synthesized willows. My question is, "When are they automatically allocated?" I would expect them to be part of myself so that I can see them in the debugger, but it seems that the only way to see them is to call the accessor method (via the gdb 'po' command). Isn't there space in the class / object structure (as it would be for an explicitly declared ivar)?

(Is there a description of the in-memory representation for a modern Objective-C object?)

As a C guy, I am very uncomfortable not seeing where everything is. :-P

+6
source share
3 answers

It looks like this will tell you: How do automatic @synthesized ivars affect * real * sizeof (MyClass)?

I am also guy C. Why use these auto-generated? I like to look at the class and see what it holds in terms of data.

Interesting: neatly, as they took the 64-bit change to improve the situation. http://www.sealiesoftware.com/blog/archive/2009/01/27/objc_explain_Non-fragile_ivars.html

+1
source

They are added to the objective-c object (which is a C structure), different from the usual ivar, therefore, for example:

@interface TestObject : NSObject { } @property (nonatomic, assign) int theInt; @end @implementation QuartzTestView @synthesize theInt; @end 

You can directly access theInt ivar (and not property accessories):

 - (void)someMethod { theInt = 5; } 

OR

 - (void)someOtherMethod { self->theInt = 10; } 
+1
source

See http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html - using the modern runtime environment, an instance variable will be synthesized. "However, it can be useful to add the variable yourself, although (so that you can see it when debugging yourself), however, you should be careful not to make direct assignments to the instance variable to save or copy based on properties.

0
source

Source: https://habr.com/ru/post/888774/


All Articles