Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestion about class members in Objective-C
    primarykey
    data
    text
    <p>I have seen the following style of defining class members; however, I have only seen it done for objects. I'm having difficulty figuring out if it will work for structures (i.e. NSUInteger or enum) and primitives (i.e. int, uint, float) as well.</p> <p>Here is my aClass.h</p> <pre><code>typedef enum { kValue0 = 0, kValue1 } CustomType; @interface aClass : CCLayerColor { NSUInteger _aMember; CustomType _anotherMember; float _aThirdMember; NSString _aFourthMember; } @property (assign) NSUInteger aMember; @property (assign) NSUInteger anotherMember; @property (assign) NSUInteger aThirdMember; @property (nonatomic, retain) NSString aFourthMember; @end </code></pre> <p>And here is my aClass.m</p> <pre><code>@implementation aClass @synthesize aMember = _aMember; @synthesize anotherMember = _anotherMember; @synthesize aThirdMember = _aThirdMember; @synthesize aFourthMember = _aFourthMember; - (id)init { if( (self=[super init] )) { NSUInteger _aMember = 100; CustomType _anotherMember = kValue0; float _aThirdMember = 200.0f; NSString _aFourthMember = [[NSString alloc] init]; } return self; } </code></pre> <p>In testing, I find that if I call the synthesized helper functions (get/set), I am able to access the member via _aMember or aMember equally well. I don't understand why, though? It seems that '@synthesize aMember = _aMember;' would only work as intended with objects, where both aMember and _aMember would point to the same memory location. I suppose I just don't understand what's happening here.</p> <p>Can anyone tell me why this works?</p> <p>Thanks, Jonathan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload