NSObject+BGPrint.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // NSObject+BGPrint.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/12/14.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "NSObject+BGPrint.h"
  9. @implementation NSObject (BGPrint)
  10. - (void)setValue:(id)value forUndefinedKey:(NSString *)key{
  11. }
  12. + (void)printfModelWithJSONDict:(NSDictionary *)dict{
  13. NSString *identifier = NSStringFromClass([self class]);
  14. [self printfModelWithClass:identifier JSONDict:dict];
  15. }
  16. + (void)printfModelWithClass:(NSString *)strClass JSONDict:(NSDictionary *)dict{
  17. printf("\n@interface %s :NSObject\n\n",strClass.UTF8String);
  18. //遍历字典
  19. for (NSString *key in dict) {
  20. NSString * type;
  21. if ([dict[key] isKindOfClass:[NSArray class]]) {
  22. type =@"NSArray";
  23. printf("@property (nonatomic,strong) %s *%s;/**<*/\n",type.UTF8String,key.UTF8String);
  24. }else if ([dict[key] isKindOfClass:[NSDictionary class]]){
  25. type =@"NSDictionary";
  26. printf("@property (nonatomic,strong) %s *%s;/**<*/\n",type.UTF8String,key.UTF8String);
  27. }else if ([dict[key] isKindOfClass:[NSNumber class]]){
  28. type =@"NSNumber";
  29. printf("@property (nonatomic,copy) %s *%s;/**<*/\n",type.UTF8String,key.UTF8String);
  30. }else if ([dict[key] isKindOfClass:[NSString class]]){
  31. type =@"NSString";
  32. printf("@property (nonatomic,copy) %s *%s;/**<*/\n",type.UTF8String,key.UTF8String);
  33. }
  34. }
  35. printf("\n@end\n");
  36. printf("@implementation %s\n\n",strClass.UTF8String);
  37. printf("@end\n");
  38. }
  39. @end