开发者

How to use the variable declared in one class in another class in Obj C

I have a NSDate *date1 in class1 implementation file(I initialized it as Global variable). I have NSDate *date2 in class 2 implement开发者_StackOverflowation 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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜