模型dict打印输出@property
来源:互联网 发布:韩国高考 知乎 编辑:程序博客网 时间:2024/06/16 13:51
我们在创建模型的时候,常常要写一大堆恶心的@property(nonatomic, copy) NSString *name;
垃圾代码,遇到这个就恶心的想吐,
给NSObject
添加一个分类,当传入一个字典会自动生成打印处理,接下来需要做的就是command + c
然后command + v
到自己的模型中
1
2
3
4
5
6
7
8
9
10
11
12
#import
@interface NSObject (propertyCode)
/**
* 自动生成属性申明Code
*
* @param dict 传入的字典
*/
+ (void)propertyCodeWithDictionary:(NSDictionary *)dict;
@end
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
#import "NSObject+propertyCode.h"
@implementationNSObject(propertyCode)
// 自动生成属性声明的代码
+(void)propertyCodeWithDictionary:(NSDictionary*)dict
{
NSMutableString*strM=[NSMutableStringstring];
[dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnullkey,id _Nonnullobj,BOOL*_Nonnullstop){
NSString*str;
NSLog(@"%@",[objclass]);
if([obj isKindOfClass:NSClassFromString(@"__NSCFString")]||[obj isKindOfClass:NSClassFromString(@"NSTaggedPointerString")]||[obj isKindOfClass:NSClassFromString(@"__NSCFConstantString")]){
str=[NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",key];
}
if([obj isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
str=[NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",key];
}
if([obj isKindOfClass:NSClassFromString(@"__NSCFArray")]){
str=[NSString stringWithFormat:@"@property (nonatomic, copy) NSArray *%@;",key];
}
if([obj isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
str=[NSString stringWithFormat:@"@property (nonatomic, copy) NSDictionary *%@;",key];
}
if([obj isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
str=[NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",key];
}
[strM appendFormat:@"\n%@\n",str];
}];
NSLog(@"%@",strM);
}
0 0
- 模型dict打印输出@property
- python格式化dict输出
- python格式化dict输出
- python基础系列教程——python将字典dict转化为xml字符串,并以不同样式打印输出
- 模型、@property、xib
- python格式化输出dict等集合对象
- kaldi 声学模型构建dict过程
- dict
- dict
- dict
- dict
- dict
- struts property输出unicode解决办法
- python---打印输出/中文输出
- Ex5_5,打印输出九九乘法表
- 打印信息输出函数
- 打印输出蛇形矩阵
- PHP输出打印函数
- HDOJ 5792 (2016多校联合训练 Training Contest 5) World is Exploding
- 使用break直接结束外层循环
- 7种形式的Android Dialog使用举例
- 文章标题
- linux与php学习杂记
- 模型dict打印输出@property
- 设计模式:责任链模式
- linux2.6.31在TX2440A上的移植
- Curl 的使用之调用接口
- hdu 4616 Game (树形dp)
- 项目中遇到的问题
- ajax中的同步与异步
- 1/n循环节长度
- 日心说和地心说