views:

142

answers:

1

I have a NSDate *date1 in class1 implementation file(I initialized it as Global variable). I have NSDate *date2 in class 2 implementation file (initialized it as Global variable). I need to calculate the NSTimeInterval between the two dates in class 2. But I could not do it. I could not access date1 in this class. It is giving error as (date2 undeclared). Please give me help in how to call other class variables in this class.

Thank you.

+1  A: 

You need to refer to date1 with extern:

// class1 file:
NSDate* date1 = nil;

// class2 file:
extern NSDate* date1;
static NSDate* date2 = nil;  // remove the static if this is needed in other files.
KennyTM
Thank you. It is very helpful to me.
srikanth rongali
hi, KennyTMCan we access the integer type variables in classB which are declared in classA by not using extern? For objects I used ClassA *obj1 = [[ClassA alloc]init]; And accessed the objects of classA into class B. But, I am not able to do them with the int , float, NSTimeInterval.How can we do for them without using extern ?Thank You.
srikanth rongali
@sri: Ask a new question.
KennyTM
Ok,Kenny. Thank You.
srikanth rongali