-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrefixHeader.pch
More file actions
executable file
·313 lines (254 loc) · 13.4 KB
/
PrefixHeader.pch
File metadata and controls
executable file
·313 lines (254 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
//$(SRCROOT)/$(PROJECT_NAME)/PrefixHeader.pch
#pragma mark - 屏幕 & 尺寸 -
//---------------------- 屏幕 & 尺寸 ----------------------------
/**
iPad Air {{0, 0}, {768, 1024}}
iphone4s {{0, 0}, {320, 480}} 960*640
iphone5 5s {{0, 0}, {320, 568}} 1136*640
iphone6 6s {{0, 0}, {375, 667}} 1334*750
iphone6Plus 6sPlus {{0, 0}, {414, 736}} 1920*1080
Apple Watch 1.65inches(英寸) 320*640
*/
#define DEF_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define DEF_SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define DEF_SCREEN_BOUNDS ([UIScreen mainScreen].bounds)
#define DEF_SCREEN_PROPORTION DEF_SCREEN_HEIGHT / DEF_SCREEN_WIDTH
#define DEF_TAB_BAR_HEIGHT 49.0f
#define DEF_STATUS_BAR_HEIGHT 20.0f
#define DEF_NIVAGATION_BAR_HEIGHT 44.0f
#define SCREEN_POINT (float)SCREEN_WIDTH/320.f
#define SCREEN_H_POINT (float)SCREEN_HEIGHT/480.f
//判断是否 Retina屏、设备是否iPhone 5、是否是iPad
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
/** 判断是否为iPhone */
#define isiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
/** 判断是否是iPad */
#define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
/** 判断是否为iPod */
#define isiPod ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
/** 设备是否为iPhone 4/4S 分辨率320x480,像素640x960,@2x */
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
/** 设备是否为iPhone 5C/5/5S 分辨率320x568,像素640x1136,@2x */
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
/** 设备是否为iPhone 6 分辨率375x667,像素750x1334,@2x */
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
/** 设备是否为iPhone 6 Plus 分辨率414x736,像素1242x2208,@3x */
#define iPhone6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#pragma mark - 系统 & 版本 -
//---------------------- 系统 & 版本 ----------------------------
//Get the OS version. 判断操作系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
//judge the simulator or hardware device 判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif
/** 获取系统版本 */
#define iOS_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue])
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
/** 是否为iOS6 */
#define iOS6 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0) ? YES : NO)
/** 是否为iOS7 */
#define iOS7 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) ? YES : NO)
/** 是否为iOS8 */
#define iOS8 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) ? YES : NO)
/** 是否为iOS9 */
#define iOS9 (([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) ? YES : NO)
/** 获取当前语言 */
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
#pragma mark - 系统时间 -
//---------------------- 系统当前时间 -------------------------
#define DATE_COMPONENTS [[NSCalendar currentCalendar] components: NSCalendarUnitNanosecond | NSCalendarUnitSecond | NSCalendarUnitMinute | NSCalendarUnitHour | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]]
#define DATE_COMPONENTS_YEAR (long)DATE_COMPONENTS.year//年
#define DATE_COMPONENTS_MOTH (long)DATE_COMPONENTS.month//月
#define DATE_COMPONENTS_DAY (long)DATE_COMPONENTS.day//日
#define DATE_COMPONENTS_HOUR (long)DATE_COMPONENTS.hour//时
#define DATE_COMPONENTS_MINUTE (long)DATE_COMPONENTS.minute//分
#define DATE_COMPONENTS_SECOND (long)DATE_COMPONENTS.second//秒
#define DATE_COMPONENTS_MILLISESCOND (long)(DATE_COMPONENTS.nanosecond * 0.000001)//毫秒
#define DATE_COMPONENTS_MICROSECOND (long)(DATE_COMPONENTS.nanosecond * 0.001)//微秒
#define DATE_COMPONENTS_NANOSESCOND (long)DATE_COMPONENTS.nanosecond//纳秒
#pragma mark - 打印日志 -
//---------------------- 打印日志 ----------------------------
//调试模式下打印日志
#ifdef DEBUG
#define DLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:@"%02ld:%02ld:%02ld:%03ld", DATE_COMPONENTS_HOUR, DATE_COMPONENTS_MINUTE, DATE_COMPONENTS_SECOND, DATE_COMPONENTS_MILLISESCOND] UTF8String], [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define DLog(FORMAT, ...)
#endif
//mark(NSString类型参数)为打印内容标题
#ifdef DEBUG
#define NSLOG_Str(mark,str) NSLog(@"##%@##--str:%@--",(mark),(str))
#define NSLOG_Int(mark,int) NSLog(@"##%@##--int:%ld--",(mark),(int))
#define NSLOG_Float(mark,float) NSLog(@"##%@##--float:%f--",(mark),(float))
#define NSLOG_Bool(mark,bool) NSLog(@"##%@##--bool:%@--",(mark),(bool) ? @"YES" : @"NO")
#define NSLOG_Point(mark,point) NSLog(@"##%@##--x:%f--y:%f--",(mark),(point).x,(point).y)
#define NSLOG_Size(mark,size) NSLog(@"##%@##--width:%f--height:%f--",(mark),(size).width,(size).height)
#define NSLOG_Frame(mark,frame) NSLog(@"##%@##--x:%f--y:%f--width:%f--height:%f--",(mark),(frame).origin.x,(frame).origin.y,(frame).size.width,(frame).size.height)
#endif
//字符串校验
#define STRINGHASVALUE(str) (str && [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length > 0)
#define IsCanUseString(str) ((str != nil) && ![str isKindOfClass:[NSNull class]] && [str isKindOfClass:[NSString class]] && [str length] > 0 )
#define IsCanUseArray(arr) ( arr && (arr != nil) && ![arr isKindOfClass:[NSNull class]] )
#define IsCanUseDic(dic) ( dic && (dic != nil) && ![dic isKindOfClass:[NSNull class]] )
#define IsCanUseObj(obj) ( obj && (obj != nil) && ![obj isKindOfClass:[NSNull class]] )
#define IsNullClass(class) [class isKindOfClass:[NSNull class]]
#pragma mark - 颜色相关 -
//---------------------- 颜色相关 ----------------------------
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
//rgb颜色转换(16进制->10进制), 格式: 0xffffff
#define HEX_COLOR(HEX) [UIColor colorWithRed:((float)((HEX & 0xFF0000) >> 16))/255.0 green:((float)((HEX & 0xFF00) >> 8))/255.0 blue:((float)(HEX & 0xFF))/255.0 alpha:1.0]
//随机颜色
#define randomTo_255 arc4random_uniform(256)
#define COLOR_Random RGBCOLOR(randomTo_255,randomTo_255,randomTo_255)
//系统颜色
#define COLOR_Clear [UIColor clearColor]
#define COLOR_White [UIColor whiteColor]
#define COLOR_Black [UIColor blackColor]
#define COLOR_Red [UIColor redColor]
#define COLOR_DarkGray [UIColor darkGrayColor]
#define COLOR_LightGray [UIColor lightGrayColor]
#define COLOR_Gray [UIColor grayColor]
#define COLOR_Green [UIColor greenColor]
#define COLOR_Blue [UIColor blueColor]
#define COLOR_Cyan [UIColor cyanColor]
#define COLOR_Yellow [UIColor yellowColor]
#define COLOR_Magenta [UIColor magentaColor]
#define COLOR_Orange [UIColor orangeColor]
#define COLOR_Purple [UIColor purpleColor]
#define COLOR_Brown [UIColor brownColor]
#pragma mark - UI操作 -
//---------------------- UI操作 -----------------------------------
/*修改frame对象的x、y、width、height属性值*/
#define FRAME_CHANGE_X(aFrame,x) CGRectMake(x, (aFrame).origin.y, (aFrame).size.width, (aFrame).size.height)
#define FRAME_CHANGE_Y(aFrame,y) CGRectMake((aFrame).origin.x, y, (aFrame).size.width, (aFrame).size.height)
#define FRAME_CHANGE_WIDTH(aFrame,w) CGRectMake((aFrame).origin.x, (aFrame).origin.y, w, (aFrame).size.height)
#define FRAME_CHANGE_HEIGHT(aFrame,h) CGRectMake((aFrame).origin.x, (aFrame).origin.y, (aFrame).size.width, h)
//获取frame的x、y、width、height
#define FRAME_GET_X(aFrame) (aFrame).origin.x
#define FRAME_GET_Y(aFrame) (aFrame).origin.y
#define FRAME_GET_WIDTH(aFrame) (aFrame).size.width
#define FRAME_GET_HEIGHT(aFrame) (aFrame).size.height
//获取Image的宽高
#define IMG_ImgWidth(img) ((img).size.width)
#define IMG_ImgHeight(img) ((img).size.height)
//获取当前的keyWindow
#define KEYWINDOW [UIApplication sharedApplication].keyWindow
#pragma mark - 线程操作 -
//---------------------- 线程操作 ----------------------------------
#define GCDWithGlobal(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define GCDWithMain(block) dispatch_async(dispatch_get_main_queue(),block)
//在主线程上执行
#define dispatch_main_async_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}
//在子线程上执行
#define dispatch_main_async_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}
//判断当前是子线程还是主线程
#define ifChildThread if (![NSThread isMainThread]) {
//填写代码
#define elseMainThread } else {
//填写代码
#define endifThread }
#pragma mark - 路径 & 文件夹 -
//---------------------- 路径 & 文件夹 -----------------------------
//存储偏好设置
#define UserDefaultSetObjectForKey(__VALUE__,__KEY__) { \
[[NSUserDefaults standardUserDefaults] setObject:__VALUE__ forKey:__KEY__]; \
[[NSUserDefaults standardUserDefaults] synchronize]; \
}
//获得偏好设置
#define UserDefaultObjectForKey(__KEY__) [[NSUserDefaults standardUserDefaults] objectForKey:__KEY__]
//删除偏好设置
#define UserDefaultRemoveObjectForKey(__KEY__) { \
[[NSUserDefaults standardUserDefaults] removeObjectForKey:__KEY__]; \
[[NSUserDefaults standardUserDefaults] synchronize]; \
}
//用户Document文件夹
#define kPathDocument NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject
#define kPathLibrary NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject
#define kPathTemp NSTemporaryDirectory()
#define kPathCaches NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).lastObject
#define kPathPreference [kPathLibrary stringByAppendingPathComponent:@"Preferences"]
//AFN缓存Coockies文件夹
#ifdef _AFNETWORKING_
#define AFN_Cookies [kPathCaches stringByAppendingPathComponent:@"Cookies"]
#endif
//SDWebImage图片缓存文件夹
#define SDWebImage_Cache [kPathCaches stringByAppendingPathComponent:@"default"]
#pragma mark - weak-strong dance -
//---------------------- weak-strong dance ------------------------
/**
@code
@weakify(self);
//在Block外部声明了一个指向self的弱指针__weak__self
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//此时, self已经是指向__weak__self的强指针了
@strongify(self);
NSLog(@"%@", self);
}];
*/
#if DEBUG
#define keywordify autoreleasepool {}
#else
#define keywordify try {} @catch (...) {}
#endif
#ifndef weakify
#if __has_feature(objc_arc)
#define weakify(VAL) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
keywordify __weak __typeof__(VAL) __weak_##VAL##__ = VAL; \
_Pragma("clang diagnostic pop")
#else
#define weakify(VAL) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
keywordify __block __typeof__(VAL) __block_##VAL##__ = VAL; \
_Pragma("clang diagnostic pop")
#endif
#endif
#ifndef strongify
#if __has_feature(objc_arc)
#define strongify(VAL) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
keywordify __strong __typeof__(VAL) VAL = __weak_##VAL##__; \
_Pragma("clang diagnostic pop")
#else
#define strongify(VAL) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
keywordify __typeof__(VAL) VAL = __block_##VAL##__; \
_Pragma("clang diagnostic pop")
#endif
#endif
#pragma mark - 其他 -
//---------------------- 其他 -------------------------------------
#define intToStr(S) [NSString stringWithFormat:@"%d",S]
/** 快速查询一段代码的执行时间 */
/** 用法
TICK
do your work here
TOCK
*/
#define TICK NSDate *startTime = [NSDate date];
#define TOCK NSLog(@"Time:%f", -[startTime timeIntervalSinceNow]);
#endif /* PrefixHeader_pch */