NSObject+MJProperty.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // NSObject+MJProperty.h
  3. // MJExtensionExample
  4. //
  5. // Created by MJ Lee on 15/4/17.
  6. // Copyright (c) 2015年 小码哥. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "MJExtensionConst.h"
  10. @class MJProperty;
  11. /**
  12. * 遍历成员变量用的block
  13. *
  14. * @param property 成员的包装对象
  15. * @param stop YES代表停止遍历,NO代表继续遍历
  16. */
  17. typedef void (^MJPropertiesEnumeration)(MJProperty *property, BOOL *stop);
  18. /** 将属性名换为其他key去字典中取值 */
  19. typedef NSDictionary * (^MJReplacedKeyFromPropertyName)(void);
  20. typedef id (^MJReplacedKeyFromPropertyName121)(NSString *propertyName);
  21. /** 数组中需要转换的模型类 */
  22. typedef NSDictionary * (^MJObjectClassInArray)(void);
  23. /** 用于过滤字典中的值 */
  24. typedef id (^MJNewValueFromOldValue)(id object, id oldValue, MJProperty *property);
  25. /**
  26. * 成员属性相关的扩展
  27. */
  28. @interface NSObject (MJProperty)
  29. #pragma mark - 遍历
  30. /**
  31. * 遍历所有的成员
  32. */
  33. + (void)mj_enumerateProperties:(MJPropertiesEnumeration)enumeration;
  34. #pragma mark - 新值配置
  35. /**
  36. * 用于过滤字典中的值
  37. *
  38. * @param newValueFormOldValue 用于过滤字典中的值
  39. */
  40. + (void)mj_setupNewValueFromOldValue:(MJNewValueFromOldValue)newValueFormOldValue;
  41. + (id)mj_getNewValueFromObject:(__unsafe_unretained id)object oldValue:(__unsafe_unretained id)oldValue property:(__unsafe_unretained MJProperty *)property;
  42. #pragma mark - key配置
  43. /**
  44. * 将属性名换为其他key去字典中取值
  45. *
  46. * @param replacedKeyFromPropertyName 将属性名换为其他key去字典中取值
  47. */
  48. + (void)mj_setupReplacedKeyFromPropertyName:(MJReplacedKeyFromPropertyName)replacedKeyFromPropertyName;
  49. /**
  50. * 将属性名换为其他key去字典中取值
  51. *
  52. * @param replacedKeyFromPropertyName121 将属性名换为其他key去字典中取值
  53. */
  54. + (void)mj_setupReplacedKeyFromPropertyName121:(MJReplacedKeyFromPropertyName121)replacedKeyFromPropertyName121;
  55. #pragma mark - array model class配置
  56. /**
  57. * 数组中需要转换的模型类
  58. *
  59. * @param objectClassInArray 数组中需要转换的模型类
  60. */
  61. + (void)mj_setupObjectClassInArray:(MJObjectClassInArray)objectClassInArray;
  62. @end