2014-04-04 23 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