原文地址:http://blog.csdn.net/kodeyang/article/details/10493973
Prefix.pch 中引入的头文件、定义的宏可以在整个工程的范围内被使用,
不过有一个弊端,只要你对 Prefix.pch 文件略作修改,就将导致重新编译所有源码文件。
下面是我所常用的一种 Prefix.pch 配置:
Prefix.pch
- #ifdef __OBJC__
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- #endif
- /**
- * 获取 Scene 对象的快捷方法
- */
- #define SCENE_FUNC(__TYPE__) \
- static CCScene* scene() { \
- CCScene* t_pScene = CCScene::create(); \
- __TYPE__* t_pLayer = __TYPE__::create(); \
- t_pScene->addChild(t_pLayer); \
- return t_pScene; \
- }
- /**
- * 打印 CCDictionary~
- */
- #define CCDICT_ECHO(__DICT__) \
- do { \
- CCDictElement* t_pDictElement = NULL; \
- CCDICT_FOREACH(__DICT__, t_pDictElement) { \
- const char* tmp_pArrCharKey = t_pDictElement->getStrKey(); \
- CCString* tmp_pCcStrVal = (CCString*)t_pDictElement->getObject(); \
- const char* tmp_pArrCharVal = tmp_pCcStrVal->getCString(); \
- printf("+++ [key = %s, value = %s] +++\n", tmp_pArrCharKey, tmp_pArrCharVal); \
- } \
- } while(0)
- /**
- * 单例~
- */
- #define sDirector CCDirector::sharedDirector()
- #define sUserDefault CCUserDefault::sharedUserDefault()
- #define sTexCache CCTextureCache::sharedTextureCache()
- #define sFrameCache CCSpriteFrameCache::sharedSpriteFrameCache()
- /**
- * 命名空间~
- */
- #define USING_NS_STD using namespace std
- /**
- * 从绝对路径获取文件名~
- */
- #define __FILE_NAME__ ((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)
- /**
- * 调试打印~
- */
- #ifdef DEBUG
- #define KYLog(fmt, ...) \
- printf(("【文件】%s\n【方法】%s\n【行号】%d\n" fmt "\n【结束】\n\n"), __FILE_NAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
- #else
- #define KYLog(...);
- #endif
- /**
- * 带开关,带换行的 log
- */
- #ifdef DEBUG
- #define println(fmt, ...) printf((fmt "\n"), ##__VA_ARGS__);
- #else
- #define println(...);
- #endif
PS:
【编程好习惯】精确包含头文件 http://blog.csdn.net/wk3368/article/details/39495481