xcode PCH的使用

301 阅读1分钟

#ifdef __OBJC__

//小技巧: #ifdef __OBJC__ 如果使用这个宏, 会保证引用的头文件将来值会导入到. m 文件中
//.c .h .m .mm .cpp

#ifdef __OBJC__
/** 配置文件*/

#import "HMConst.h"

/** 分类*/

#import "UIView+HMCategory.h"

#import "UIBarButtonItem+HMCategory.h"

/** 第三方库*/

#import <YYModel/YYModel.h>

#import <Masonry/Masonry.h>

#import "UIView+AutoLayout.h"

#endif

NSString常量

在PCH里面:

#ifdef __OBJC__

/** 配置文件*/
#import "HMConst.h"

#endif

新建文件:

.h:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

// 如果是 CGFloat等 类型
const CGFloat width = 7;
// extern : 引用本类或者其他类中使用
// 城市通知
extern NSString *const HMCityDidChangeNotifacation;
extern NSString *const HMSelectCityName;

.m:

/**
 常量值
 .m 文件中进行赋值  const:标识后面的东西是不可修改的
 */
 NSString *const HMCityDidChangeNotifacation = @"HMCityDidChangeNotifacation";

NSLog

会打印语句所在的文件和行数

/** NSLog 输出宏*/

#ifdef DEBUG

#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define NSLog(...)

#endif