2014-04-04 17 views
-1

这是我的代码:Objective-c中的XCTestCase中的类变量?

#import <XCTest/XCTest.h> 
#import "GTN_GameStatistics.h" 


@interface GTN_GameStatisticsTest : XCTestCase 

@end 

@implementation GTN_GameStatisticsTest{ 
    GTN_GameStatistics * _gameStatistic; 
} 

+ (void)setUp 
{ 
    [super setUp]; 
    // Put setup code here; it will be run once, before the first test case. 

} 

- (void)setUp 
{ 
    [super setUp]; 
    // Put setup code here; it will be run once, before the first test case. 

    _gameStatistic = [GTN_GameStatistics sharedManager]; 
} 

- (void)tearDown 
{ 
    // Put teardown code here; it will be run once, after the last test case. 
    [super tearDown]; 

    [_gameStatistic resetStatistics]; 
} 

是否有某种方式把代码- (void)setUp至+ (void)setUp
为此我需要使GTN_GameStatistics * _gameStatistic一个类变量不是实例变量,但我不知道如何。
我尝试了一些方法,但它没有奏效。
我可以做到这一点,但想知道这是可能的和如何?

+0

请使用'xcode'标签只可用于与IDE本身的问题。 –

+0

@Leo OK。谢谢。 – WebOrCode

回答

1

有没有这样的事情作为“类变量”,但一个全局变量伎俩。下面您#imports:

static GTN_GameStatistics * _gameStatistic; 

然后在您的+设置方法:

_gameStatistic = [GTN_GameStatistics sharedManager]; 
+0

C++有它,所以我认为objective-c也有它。 – WebOrCode