MGBaseModel.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // MGBaseModel.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/6/17.
  6. // Copyright © 2019年 xfg. All rights reserved.
  7. //
  8. #import "MGBaseModel.h"
  9. @implementation MGBaseModel
  10. - (id)initWithDictionary:(NSDictionary *)dic
  11. {
  12. if (![dic isKindOfClass:[NSDictionary class]]) {
  13. return nil;
  14. }
  15. self = [super init];
  16. if (self) {
  17. [self setAttributesFromDictionary:dic];
  18. }
  19. return self;
  20. }
  21. - (void)setAttributesFromDictionary:(NSDictionary *)aDictionary {
  22. if (![aDictionary isKindOfClass:[NSDictionary class]]) {
  23. return;
  24. }
  25. [self setValuesForKeysWithDictionary:aDictionary];
  26. }
  27. -(void)setValue:(id)value forUndefinedKey:(NSString *)key
  28. {
  29. }
  30. //- (NSString *)description
  31. //{
  32. // NSMutableString *des = [NSMutableString string];
  33. //
  34. // unsigned int allCount;
  35. //
  36. // objc_property_t *properties = class_copyPropertyList([self class], &allCount);
  37. //
  38. // for (int i = 0; i < allCount; i ++) {
  39. // @autoreleasepool {
  40. // objc_property_t property = properties[i];
  41. // NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
  42. // id propertyValue = [self valueForKey:propertyName];
  43. //
  44. // if (nil == propertyValue || [NSNull null] == (NSNull *)propertyValue) {
  45. // propertyValue = @"";
  46. // }
  47. //
  48. // if (i < allCount - 1) {
  49. // [des appendFormat:@"%@:'%@',",propertyName,propertyValue];
  50. // }else
  51. // {
  52. // [des appendFormat:@"%@:'%@'",propertyName,propertyValue];
  53. // }
  54. // }
  55. // }
  56. //
  57. // return des;
  58. //}
  59. @end