object-c cocos2d-x 寫程式時注意除錯的技巧

OpenSoucre發表於2013-07-17

(1)寫程式時最好在類的init函式中顯示類名,表明現在在執行哪個類,樣例程式碼

       CCLOG(@"cocos2d: Using Director Type:%@", [self class]);

(2)最好在類中新增一個描述該類相關資訊的函式,樣例程式碼:

- (NSString*) description
{
	return [NSString stringWithFormat:@"<%@ = %p | Size: %0.f x %0.f, view = %@>", [self class], self, winSizeInPoints_.width, winSizeInPoints_.height, view_];
}

(3)在每個函式中新增一個描述函式名有關的資訊,樣例程式碼:

 CCLOG(@"%@: Using Method Type:%@", [self class],[self _cmd]);

 (4) 對某些值可以加上斷言

NSAssert(_sharedDirector == nil, @"Attempted to allocate a second instance of a singleton.");

 (5)要善於運用條件編譯,去除錯程式碼

#ifdef DEBUG
	// If we are debugging our code
    ............................
#endif

  

 

  

相關文章