使用代码自动创建模型属性
来源:互联网 发布:淘宝 婚礼 成长视频 编辑:程序博客网 时间:2024/05/19 06:38
每次Model中有很多的属性,写起来很费劲!这篇文章将实现一句话创建Model中的所有属性代码,输出到控制台!!!
NSObject+Property.h
#import <Foundation/Foundation.h>@interface NSObject (Property)+ (void)createPropertyCodeWithDictionary:(NSDictionary *)dictionary;@end
NSObject+Property.m
#import "NSObject+Property.h"@implementation NSObject (Property)+ (void)createPropertyCodeWithDictionary:(NSDictionary *)dictionary{ NSMutableString *strM = [NSMutableString string]; // 遍历字典 [dictionary enumerateKeysAndObjectsUsingBlock:^(id _Nonnull propertyName, id _Nonnull value, BOOL * _Nonnull stop) { // NSLog(@"%@ %@",propertyName,[value class]); NSString *code; if ([value isKindOfClass:NSClassFromString(@"__NSCFString")]) { code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",propertyName] ; }else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){ code = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",propertyName] ; }else if ([value isKindOfClass:NSClassFromString(@"__NSCFArray")]){ code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",propertyName] ; }else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){ code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName] ; }else { //未完待续...... } [strM appendFormat:@"\n%@\n",code]; }]; NSLog(@"%@",strM);}@end
更多内容--> 博客导航 每周一篇哟!!!
有任何关于iOS开发的问题!欢迎下方留言!!!或者邮件lieryangios@126.com 虽然我不一定能够解答出来,但是我会请教iOS开发高手!!!解答您的问题!!!
阅读全文
0 0
- 使用代码自动创建模型属性
- iOS-自动生成模型属性代码
- 使用MyBatis自动创建代码
- 使用自动属性减少代码输入量
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用mybatis generator自动创建代码
- [SSM]使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- 使用MyBatis Generator自动创建代码
- Linux启动/停止/重启gitlab
- Struts2入门(7): 注解
- CSS 浮动规则
- exec族函数
- mysql悲观锁与乐观锁
- 使用代码自动创建模型属性
- jeesite导入导出前端(.jsp)+controller
- 试一下
- 1010: [HNOI2008]玩具装箱toy
- python设置中文编码
- 【tree 反转二叉树 inverse binary tree】
- 原子操作,自旋锁,互斥锁,信号量学习
- android检测arp攻击
- Struts2入门(8):OSNL & 标签库