使用代码自动创建模型属性
2017-08-12 15:33
281 查看
每次Model中有很多的属性,写起来很费劲!这篇文章将实现一句话创建Model中的所有属性代码,输出到控制台!!!
NSObject+Property.h
NSObject+Property.m
更多内容--> 博客导航 每周一篇哟!!!
有任何关于iOS开发的问题!欢迎下方留言!!!或者邮件lieryangios@126.com 虽然我不一定能够解答出来,但是我会请教iOS开发高手!!!解答您的问题!!!
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开发高手!!!解答您的问题!!!
相关文章推荐
- 使用代码自动创建模型属性
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- 使用MyBatis Generator自动创建代码
- SSM框架——使用MyBatis Generator自动创建代码
- [转]使用新的代码和标记模型创建真实的应用程序
- 使用自动属性减少代码输入量
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- Myeclipse 10 使用mybatis-generator自动创建代码总结,附源码
- SSM框架——使用MyBatis Generator自动创建代码
- Spring学习笔记---使用MyBatis Generator自动创建代码
- SSM框架——使用MyBatis Generator自动创建代码
- jquery 自动创建form表单提交代码 下拉条 ajax模板代码 添加_移除 属性_样式
- SSM框架——使用MyBatis Generator自动创建代码
- SSM框架——使用MyBatis Generator自动创建代码
- Setting the defaults for database access——使用createTables.php自动创建数据模型
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象(反射机制)
- SSM框架——使用MyBatis Generator自动创建代码
- Android 在Java代码中设置style属性--使用代码创建ProgressBar对象