Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm going to assume the question involves a class, <code>ClassOne</code>, with an instance variable <code>int integerOne</code>, which you'd like to access from another class, <code>ClassTwo</code>. The best way to handle this is to create a property in <code>ClassOne</code>. In ClassOne.h:</p> <pre><code>@property (assign) int integerOne; </code></pre> <p>This declares a property (basically, two methods, <code>- (int)integerOne</code>, and <code>- (void)setIntegerOne:(int)newInteger</code>). Then, in ClassOne.m:</p> <pre><code>@synthesize integerOne; </code></pre> <p>This "synthesizes" the two methods for you. This is basically equivalent to:</p> <pre><code>- (int)integerOne { return integerOne; } - (void)setIntegerOne:(int)newInteger { integerOne = newInteger; } </code></pre> <p>At this point, you can now call these methods from <code>ClassTwo</code>. In ClassTwo.m:</p> <pre><code>#import "ClassOne.h" //Importing ClassOne.h will tell the compiler about the methods you declared, preventing warnings at compilation - (void)someMethodRequiringTheInteger { //First, we'll create an example ClassOne instance ClassOne* exampleObject = [[ClassOne alloc] init]; //Now, using our newly written property, we can access integerOne. NSLog(@"Here's integerOne: %i",[exampleObject integerOne]); //We can even change it. [exampleObject setIntegerOne:5]; NSLog(@"Here's our changed value: %i",[exampleObject integerOne]); } </code></pre> <p>It sounds like you should walk through a few tutorials to learn these Objective-C concepts. I suggest <a href="https://stackoverflow.com/questions/1362476/whats-the-best-resource-to-learn-how-to-write-apps-for-mac-os-x/1362595#1362595">these</a>.</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