Skip to content
This repository was archived by the owner on Sep 6, 2019. It is now read-only.

Commit 8d97e5a

Browse files
committed
添加 DebugDescription 分类,打印模型时打印其下元素。
1 parent b9e7a42 commit 8d97e5a

File tree

4 files changed

+121
-33
lines changed

4 files changed

+121
-33
lines changed

README.md

+43-32
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# RKOTools
22

3-
自己平时写的一个小工具库,上传到**GitHub**中且支持`CocoaPods`,方便自己使用。不断更新完善中。
3+
自己平时写的一个小工具库,上传到 **GitHub** 中且支持 `CocoaPods` ,方便自己使用。不断更新完善中。
44

5-
**注意:**`1.4.0`之前的版本集成了自己写的一些控件,从`1.4.0`版本开始,这些控件不再集成到`RKOTools`库中了,将会单独提供并支持`CocoaPods`。该页面则做目录之用,将会列出所有控件。
5+
**注意:** `1.4.0` 之前的版本集成了自己写的一些控件,从 `1.4.0` 版本开始,这些控件不再集成到 `RKOTools` 库中了,将会单独提供并支持 `CocoaPods` 。该页面则做目录之用,将会列出所有控件。
66

77
<p align="center">
8-
<a href=""><img src="https://img.shields.io/badge/pod-v1.4.2-brightgreen.svg"></a>
8+
<a href=""><img src="https://img.shields.io/badge/pod-v1.4.3-brightgreen.svg"></a>
99
<a href=""><img src="https://img.shields.io/badge/ObjectiveC-compatible-orange.svg"></a>
1010
<a href=""><img src="https://img.shields.io/badge/platform-iOS%208.0%2B-ff69b5152950834.svg"></a>
1111
<a href="https://github.com/rakuyoMo/RKOTools/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg?style=flat"></a>
@@ -21,7 +21,8 @@
2121
5. [TopViewController](#topviewcontroller)
2222
6. [UIView+StoryBoard](#uiviewstoryboard)
2323
7. [ImageWithColor](#imagewithcolor)
24-
8. [~~FastFrame~~](#fastframe)
24+
8. [DebugDescription](#debugdescription)
25+
9. [~~FastFrame~~](#fastframe)
2526
2. [RKOControl](#rkocontrol)
2627
3. [BLOG](#blog)
2728

@@ -32,14 +33,14 @@
3233
### 集成:
3334

3435
```shell
35-
pod 'RKOTools', '~> 1.4.2'
36+
pod 'RKOTools', '~> 1.4.3'
3637
```
3738

3839
---------------------------------------------------------------------
3940

4041
### RKOCell
4142

42-
`xib`或者自定义`Cell`中快速获取`Cell`的一个小工具。接口如下所示:
43+
`xib` 或者自定义 `Cell` 中快速获取 `Cell` 的一个小工具。接口如下所示:
4344

4445
```objc
4546
/**
@@ -71,7 +72,7 @@
7172

7273
### NetWorkTool
7374

74-
自定义封装的`AFNetworking`。初学乍道还不是很完善。
75+
自定义封装的 `AFNetworking` 。初学乍道还不是很完善。
7576

7677
<br>接口提供如下几个**宏定义**
7778

@@ -94,9 +95,9 @@ UIKIT_EXTERN NSString * const diskPath;
9495
UIKIT_EXTERN NSString * const baseURL;
9596
```
9697

97-
- 注意:在`RKONetWorkTool.h`文件中,为了避免添加到CocoaPods不通过,对`diskPath``baseURL`进行了定义。在您使用的时候建议进行删除,将定义写在您的代码中。
98+
- 注意:在 `RKONetWorkTool.h` 文件中,为了避免添加到CocoaPods不通过,对 `diskPath``baseURL` 进行了定义。在您使用的时候建议进行删除,将定义写在您的代码中。
9899

99-
<br>`RKONetWorkTool`提供7个方法,声明如下:
100+
<br> `RKONetWorkTool` 提供7个方法,声明如下:
100101

101102
**POST方法:**
102103
```objc
@@ -224,7 +225,7 @@ UIKIT_EXTERN NSString * const baseURL;
224225
+ (instancetype)sharedManager;
225226
```
226227

227-
提供一个协议`RKONetWorkToolDelegate`,协议声明如下:
228+
提供一个协议 `RKONetWorkToolDelegate` ,协议声明如下:
228229

229230
```objc
230231
/**
@@ -239,27 +240,27 @@ UIKIT_EXTERN NSString * const baseURL;
239240
@end
240241
```
241242
242-
遵守该协议并实现`networkStaAlertWithNetWorkTool:`方法,即可设置在无网络时的弹窗提示。
243+
遵守该协议并实现 `networkStaAlertWithNetWorkTool:` 方法,即可设置在无网络时的弹窗提示。
243244
244245
---------------------------------------------------------------------
245246
246247
### CloseKeyBoard
247248
248-
`UITableView`的分类,点击空白处关闭键盘的小工具。在需要的地方引入头文件即可
249+
`UITableView` 的分类,点击空白处关闭键盘的小工具。在需要的地方引入头文件即可
249250
<br><br>转载自简书:<br>
250251
[iOS利用响应链机制点击tableview空白处关闭键盘](http://www.jianshu.com/p/9717b792599c)**评论中**的**鱼鱼鱼四只鱼**提供的代码。
251252
252253
---------------------------------------------------------------------
253254
254255
### CollecionLog
255256
256-
`NSDictionary``NSArray`的分类,拼接字符串,解决字典和数组中输出中文的时候是`unicode`编码的问题
257+
`NSDictionary``NSArray` 的分类,拼接字符串,解决字典和数组中输出中文的时候是 `unicode` 编码的问题
257258
258259
---------------------------------------------------------------------
259260
260261
### TopViewController
261262
262-
`UIViewController`的分类,用来获取当前界面真在显示的`ViewController`,接口部分如下所示:
263+
`UIViewController` 的分类,用来获取当前界面真在显示的 `ViewController` ,接口部分如下所示:
263264
264265
```objc
265266
@interface UIViewController (RKOTopViewController)
@@ -269,33 +270,33 @@ UIKIT_EXTERN NSString * const baseURL;
269270
@end
270271
```
271272

272-
在需要的地方导入头文件,调用`topViewController`方法即可。
273+
在需要的地方导入头文件,调用 `topViewController` 方法即可。
273274

274275
---------------------------------------------------------------------
275276

276277
### UIView+StoryBoard
277278

278-
原先 `CALayer+Additions`的代替品。
279+
原先 `CALayer+Additions` 的代替品。
279280

280-
`UIView`的分类。使用~~`IB_DESIGNABLE`~~`IBInspectable`,可以在`StoryBoard`中快速设置视图**圆角****边框**以及**阴影**
281+
`UIView` 的分类。使用~~`IB_DESIGNABLE`~~ `IBInspectable` ,可以在 `StoryBoard` 中快速设置视图**圆角****边框**以及**阴影**
281282

282283
~~并且提供一个空白的`UIView`子类`RKOBaseStoryBoardView`,如果您在`StoryBoard`中的空白`UIView`需要**所见即所得**,那么可以选择关联到该类上。~~
283284

284285
具体来说我们提供的属性如下:
285286

286287
```objc
287288
/** 圆角。 */
288-
@property(nonatomic,assign) IBInspectable CGFloat cornerRadius;
289+
@property (nonatomic,assign) IBInspectable CGFloat cornerRadius;
289290

290291
/** 边框宽度和颜色。 */
291-
@property(nonatomic,assign) IBInspectable CGFloat borderWidth;
292-
@property(nonatomic,strong) IBInspectable UIColor *borderColor;
292+
@property (nonatomic,assign) IBInspectable CGFloat borderWidth;
293+
@property (nonatomic,strong) IBInspectable UIColor *borderColor;
293294

294295
/** 阴影。 */
295-
@property(nonatomic,assign) IBInspectable float shadowOpacity;
296-
@property(nonatomic,strong) IBInspectable UIColor *shadowColor;
297-
@property(nonatomic,assign) IBInspectable CGFloat shadowRadius;
298-
@property(nonatomic,assign) IBInspectable CGSize shadowOffset;
296+
@property (nonatomic,assign) IBInspectable float shadowOpacity;
297+
@property (nonatomic,strong) IBInspectable UIColor *shadowColor;
298+
@property (nonatomic,assign) IBInspectable CGFloat shadowRadius;
299+
@property (nonatomic,assign) IBInspectable CGSize shadowOffset;
299300
```
300301

301302
`StoryBoard`中如下所示:
@@ -314,7 +315,7 @@ UIKIT_EXTERN NSString * const baseURL;
314315

315316
### ImageWithColor
316317

317-
`UIImage`的分类方法,可以根据某一颜色生成一张图片,方便设置`UIButton`的背景图。
318+
`UIImage` 的分类方法,可以根据某一颜色生成一张图片,方便设置 `UIButton` 的背景图。
318319

319320
使用时调用下面的方法,传入颜色即可。
320321

@@ -324,17 +325,27 @@ UIKIT_EXTERN NSString * const baseURL;
324325

325326
---------------------------------------------------------------------
326327

328+
### DebugDescription
329+
330+
`NSObject` 的分类。方便我们在使用诸如 `NSLog``po` 打印模型时,输出其下元素的具体内容而非单一地址。
331+
332+
重写了 `debugDescription` 方法和 `description`。无需调用,集成到项目中就可以直接使用。
333+
334+
参照 [iOS模型打印](http://www.cocoachina.com/ios/20170728/20055.html) 编写。
335+
336+
---------------------------------------------------------------------
337+
327338
### FastFrame
328339

329-
**因其与**[Masonry](https://github.com/SnapKit/Masonry)**冲突,故从库中删除**。如果您有需要,可查找[1.1.0](https://github.com/rakuyoMo/RKOTools/releases/tag/1.1.0)版本的历史记录,查看相关代码与记录在`README`文件中的API说明
340+
**因其与** [Masonry](https://github.com/SnapKit/Masonry) **冲突,故从库中删除**。如果您有需要,[点击这里](https://github.com/rakuyoMo/RKOTools/commit/79426847a70577038c93f1d1a95bd887577f13d7) ,查看相关代码与记录在 `README` 文件中的 API 说明
330341

331342
---------------------------------------------------------------------
332343

333344
## RKOControl
334345

335-
安利一下自己写的另外一个控件库。原本和`RKOTools`在一个库下,后来觉得有点冗余所以分成了两个库。
346+
安利一下自己写的另外一个控件库。原本和 `RKOTools` 在一个库下,后来觉得有点冗余所以分成了两个库。
336347

337-
下面几个都是封装的一些**小控件**。具体介绍不再在该页面提供,请点击对应的**Github**页面查看。
348+
下面几个都是封装的一些**小控件**。具体介绍不再在该页面提供,请点击对应的 **Github** 页面查看。
338349

339350
---------------------------------------------------------------------
340351

@@ -360,7 +371,7 @@ UIKIT_EXTERN NSString * const baseURL;
360371
### RKOTextView
361372

362373
<p align="left">
363-
<a href=""><img src="https://img.shields.io/badge/pod-v1.0.5-brightgreen.svg"></a>
374+
<a href=""><img src="https://img.shields.io/badge/pod-v1.1.0-brightgreen.svg"></a>
364375
<a href=""><img src="https://img.shields.io/badge/ObjectiveC-compatible-orange.svg"></a>
365376
<a href=""><img src="https://img.shields.io/badge/platform-iOS%207.0%2B-ff69b5152950834.svg"></a>
366377
<a href="https://github.com/rakuyoMo/RKOTools/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green.svg?style=flat"></a>
@@ -371,7 +382,7 @@ UIKIT_EXTERN NSString * const baseURL;
371382
#### 集成:
372383

373384
```shell
374-
pod 'RKOTextView', '~> 1.0.5'
385+
pod 'RKOTextView', '~> 1.1.0'
375386
```
376387

377388
---------------------------------------------------------------------
@@ -397,11 +408,11 @@ UIKIT_EXTERN NSString * const baseURL;
397408

398409
### RKOTabBar
399410

400-
封装的一个`TabBar`,但是效果并是很好....想了想还是不放在这里了,几乎用不到,每次都要删除怪麻烦的。
411+
封装的一个 `TabBar` ,但是效果并是很好....想了想还是不放在这里了,几乎用不到,每次都要删除怪麻烦的。
401412

402413
---------------------------------------------------------------------
403414

404415
## BLOG
405416

406-
本人课余时间利用`HEXO`在GitHub上搭建的博客。未来部分工具会有对应的blog文章对应。在这里也把blog的地址贴出来吧:<br><br>
417+
本人课余时间利用 `HEXO` 在 GitHub 上搭建的博客。未来部分工具会有对应的 blog 文章对应。在这里也把 blog 的地址贴出来吧:<br><br>
407418
<a href="https://rakuyomo.github.io" target="_blank">喵喵喵</a>

RKOTools.podspec

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Pod::Spec.new do |s|
1010

1111
s.name = "RKOTools"
12-
s.version = "1.4.2"
12+
s.version = "1.4.3"
1313
s.summary = "One of your own tool libraries"
1414
s.description = <<-DESC
1515
One of your own tool libraries
@@ -64,4 +64,9 @@ Pod::Spec.new do |s|
6464
imageWithColor.source_files = "RKOTools/ImageWithColor/*.{h,m}"
6565
end
6666

67+
s.subspec 'DebugDescription' do |debugDescription|
68+
69+
debugDescription.source_files = "RKOTools/DebugDescription/*.{h,m}"
70+
end
71+
6772
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// NSObject+DebugDescription.h
3+
// DebugDescription
4+
//
5+
// Created by Rakuyo on 2017/10/6.
6+
// Copyright © 2017年 Rakuyo. All rights reserved.
7+
//
8+
// http://www.cocoachina.com/ios/20170728/20055.html
9+
10+
#import <Foundation/Foundation.h>
11+
12+
// 打印模型时打印其下元素。
13+
@interface NSObject (DebugDescription)
14+
15+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// NSObject+DebugDescription.m
3+
// DebugDescription
4+
//
5+
// Created by Rakuyo on 2017/10/6.
6+
// Copyright © 2017年 Rakuyo. All rights reserved.
7+
//
8+
9+
#import "NSObject+DebugDescription.h"
10+
#import <objc/runtime.h>
11+
12+
@implementation NSObject (DebugDescription)
13+
14+
- (NSString *)description {
15+
16+
if ([self isKindOfClass:[NSArray class]]
17+
|| [self isKindOfClass:[NSDictionary class]]
18+
|| [self isKindOfClass:[NSNumber class]]
19+
|| [self isKindOfClass:[NSString class]]) {
20+
return self.description;
21+
}
22+
23+
return [self debugDescription];
24+
}
25+
26+
- (NSString *)debugDescription {
27+
if ([self isKindOfClass:[NSArray class]]
28+
|| [self isKindOfClass:[NSDictionary class]]
29+
|| [self isKindOfClass:[NSNumber class]]
30+
|| [self isKindOfClass:[NSString class]]) {
31+
return self.debugDescription;
32+
}
33+
34+
// 初始化一个字典
35+
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
36+
37+
// 得到当前 Class 的所有属性
38+
uint count;
39+
objc_property_t *properties = class_copyPropertyList([self class], &count);
40+
41+
// 利用KVC获取属性值
42+
for (int i = 0; i < count; i++) {
43+
objc_property_t property = properties[i];
44+
NSString *name = @(property_getName(property));
45+
46+
// 设置一个默认值。
47+
id value = [self valueForKey:name]?:@"nil";
48+
49+
[dic setObject:value forKey:name];
50+
}
51+
52+
free(properties);
53+
54+
return [NSString stringWithFormat:@"<%@: %p> -- %@", [self class], self, dic];
55+
}
56+
57+
@end

0 commit comments

Comments
 (0)