Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

srikanthrongali

macrumors newbie
Original poster
I have a ClassA, ClassB, ClassC.
In ClassA,

Code:
@interface ClassA : NSObject 
{
	NSString *enemyDescription;
	int numberOfEnemies;
}

@property(nonatomic, retain) NSString *enemyDescription;
@property(nonatomic, assign) int numberOfEnemies;
I want to use these values in classB.
I used
C
Code:
lassA * aclassA = [[ClassA alloc]init]; in classB.
So, I can get the values from ClassA and use them in ClassB.
But, I read that
Code:
ClassA * aclassA = [[ClassA alloc]init];
creates an empty object. So, we cannot access any values from ClassB in to ClassA.

But, in some cases I am able to access the values and I can see the values by using NSLog in ClassB.
Code:
NSLog("string: %@", aclassA. enemyDescription);
But, some times I see the values are 0.
What is the correct method of accessing the values from ClassA into ClassB ?
Thank you.
 
What do you mean by access?

You can always send classA setter and getter messages to access anything (not only class variables, and not only variables), if you've created the appropriate setters and getters in classA.

Other, less clean, ways include stuffing pointers to the various variables into all classes that need the access, peeking/poking directly into class structures, and etc.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.