Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing int value from another class
    text
    copied!<p>I am having trouble accessing an int property from another class. I know this question has been asked quite a few times however none of the solutions posted in previous questions seem to work. My knowledge in xcode is basic, and I am using this project to develop my skills.</p> <p>The two classes I have are: HelloWorldLayer and ClassOne. Where ClassOne states the value of int. Both are Cocos2d CCLayer classes (probably not the best class to practice inter-class value access).</p> <p><strong>ClassOne.h</strong></p> <pre><code>@interface ClassOne : CCLayer { int ageClass; } @property (nonatomic, readwrite)int ageClass; @end </code></pre> <p><strong>ClassOne.m</strong></p> <pre><code>@implementation ClassOne @synthesize ageClass = _ageClass; -(id)init{ if((self=[super init])){ _ageClass = 10; } return self; } @end </code></pre> <p><strong>HelloWorldLayer.h</strong></p> <pre><code>#import "ClassOne.h" @interface HelloWorldLayer : CCLayer &lt;...&gt; { ClassOne *agePointer; } @property (nonatomic,assign)ClassOne *agePointer; +(CCScene*)scene; @end </code></pre> <p><strong>HelloWorldLayer.m</strong></p> <pre><code>#import "HelloWorldLayer.h" #import "AppDelegate.h" #import "ClassOne.h" @implementation HelloWorldLayer @synthesize agePointer = _agePointer; +(CCScene*)scene... -(id)init{ if((self=[super init])){ _agePointer.ageClass = self; NSLog(@"ClassOne int = %@",_agePointer); } return self; } ... @end </code></pre> <p><strong>Output Result:</strong></p> <pre><code>"ClassOne int = (null)" or "0" if i use "%d" token and "int = x", where the line "int x =_agePointer.ageClass;" is used. </code></pre> <p>The result I am after is for the HelloWorldLayer NSLog to display "10", the int value defined in ClassOne.</p> <p>Any wisdom and corrections on my use of language is greatly appreciated.</p>
 

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