Quote:
Originally Posted by ozzie
If I have 2 .h and .m files and I want to pass the value of a variable between them, how would I do it?
So in Slide1.m it declares Variable1 = 10; then I want Slide2.m to be able to declare Variable2 = Variable1; but it obviously says "Variable1 undeclared (first use in a function)"
Thanks in advance 
|
If Variable1 and Variable2 are integers, then they don't have to be instance variables of any class. You can simply declare them both to be global variables. In Slide1.h, use:
Code:
extern int Variable1;
@interface Slide1
. . .
@end
and similarly for Slide2.h. And in the implementation files, use:
Code:
int Variable1;
@implementation Slide1
. . .
@end
You see that the declaration and the definition are outside of the @interface and @implementation blocks. It is up to you to ensure that there is only one instance of the Slide1 and Slide2 classes.
The problem with using instance variables, even if they are properties, is that you need to also have a reference to the instance of the class they belong to. How does Slide1.m have any pointer to an instance of Slide2? There could potentially be several Slide1 instances and several Slide2 instances. But from your description, it appears that you are thinking of just one instance of each class.
Robert Scott
Ypsilanti, Michigan