<1> MJExtensionConst
.h -- 宏定义error/log,一堆断言,宏定义重写desc方法(模型转字典打印),extern属性类型
.m -- 定义常量
<2> MJFoundation
.h -- +isClassFromFoundation:
.m -- +foundationClasses:,+isClassFromFoundation:
<3> MJProperty
.h -- +cachedPropertyWithProperty:
.m -- 2Dict-getters懒加载,
+cachedPropertyWithProperty: (懒加载_关联对象缓存) -----> setProperty:(_property,_name,_type(cachedTypeWithCode - 封装MJPropertyType))
setOriginKey:forClass: -- NSString & NSArray
--> propertyKeysWithStringKey:(多级映射stu.bag, i. 处理替换后的key(如: name.info[1].nameChangedTime) ii. MJPropertyKey)
--> setPropertyKeys:forClass: + propertyKeysForClass:(设置propertyKeysDict)
setObjectClassInArray:forClass: + objectClassInArrayForClass(objectClassInArrayDict)
valueForObject: && setValue:forObject:(KVC的一层封装)
<4> MJPropertyKey
.h -- keyName,keyType,valueInObject:
.m -- valueInObject:(根据keyType判断取值,NSDictionary & NSArray)
<5> MJPropertyType
.h -- +cachedTypeWithCode
.m -- +cachedTypeWithCode:(有从types_(缓存type)拿出,没有自创放入) -> setCode:(各种判断类型,_idType,_KVCDisabled,_code,_typeClass,_fromFoundation,_numberType,_boolType)
<1> NSObject+MJClass
.h -- 黑白名单block,mj_setupAllowedPropertyNames:+mj_totalAllowedPropertyNames,白名单/归档配置mj_setupAllowedCodingPropertyNames:+mj_totalAllowedCodingPropertyNames
mj_setupIgnoredPropertyNames:+mj_totalIgnoredPropertyNames,黑名单/归档配置mj_setupIgnoredCodingPropertyNames:+mj_totalIgnoredCodingPropertyNames
mj_setupBlockReturnValue:key:
mj_enumerate/AllClasses:(自己和父类回调enumeration)
.m -- +load:,+dictForKey:(返回黑白名单PropertyNames缓存字典)
mj_setupAllowedPropertyNames:+mj_setupAllowedCodingPropertyNames: + mj_setupIgnoredPropertyNames:+mj_setupIgnoredCodingPropertyNames: -------------> mj_setupBlockReturnValue:key: (关联黑白名单block + removeAllObjects)
mj_totalAllowedPropertyNames:+mj_totalAllowedCodingPropertyNames: +mj_totalIgnoredPropertyNames: + mj_totalIgnoredCodingPropertyNames: -------------> mj_totalObjectsWithSelector:key: (黑白名单dict取,有返回,没有,从delegate方法中拿 - 从所有自己和父类的关联对象中拿)
<2> NSObject+MJCoding
.h -- @protocol MJCoding - mj_allowed/ignoredCodingPropertyNames
mj_decode: + mj_encode: (mj_enumerateProperties:回调,黑白名单判定,encode: KVC取值 -> encodeObject:forKey:,decode: decodeObjectForKey -> KVC赋值)
归档的实现宏 - MJExtensionCodingImplementation
<3> NSString+MJExtension
.h -- mj_Underline <=> Camel,mj_firstCharUpper/Lower,mj_isPureInt,mj_url
<1> NSObject+MJKeyValue
.h -- @protocol MJKeyValue - +mj_allowed/ignoredPropertyNames,mj_replacedKeyFromPropertyName,mj_replacedKeyFromPropertyName121,mj_objectClassInArray,mj_newValueFromOldValue:property,mj_keyValuesDidFinishConvertingToObject,mj_objectDidFinishConvertingToKeyValues
-- mj_keyValues~~
mj_objectWithFilename -> mj_objectWithFile (本地Dict)
mj_objectArrayWithFilename -> mj_objectArrayWithFile (本地Array)
mj_objectWithKeyValues:context:
mj_objectArrayWithKeyValuesArray:context:
mj_keyValuesWithKeys: ignoredKeys:
mj_keyValuesArrayWithObjectArray:keys:ignoredKeys:
mj_JSONData + mj_JSONObject (NSString + NSData + mj_keyValues) + mj_JSONString
.m --
mj_error + setMj_error (关联error)
mj_referenceReplacedKeyWhenCreatingKeyValues,mj_isReferenceReplacedKeyWhenCreatingKeyValues (所有父类get关联对象)
mj_objectWithKeyValues: context:-> mj_setKeyValues:context: -> mj_enumerateProperties: ( 黑白名单,propertyKeysDict中剥洋葱到value取值,值过滤, i. 模型属性 -> 递归,ii. objectClass数组中模型(1. string array -> url array 2. mj_objectArrayWithKeyValuesArray:context: (递归)) iii. 基础类型转换 )
mj_keyValuesWithKeys: ignoredKeys: (mj_enumerateProperties: 黑白名单检测,取值, i.模型属性 -> 递归,ii. 数组里面有模型 -> mj_keyValuesArrayWithObjectArray:keys:ignoredKeys: (递归),iii. NSURL -> absoluteString,
iv.参考delegate方法(if. 枚举propertyKeysDict中array中propertyKey - (if >=2. 下一个根据类型创建加入前一个 else.只有一个,直接赋值) else. 直接赋值) )
<2> NSObject+MJProperty
.h -- block: MJPropertiesEnumeration,MJReplacedKeyFromPropertyName/121,MJObjectClassInArray,MJNewValueFromOldValue
mj_enumerateProperties:
mj_setupNewValueFromOldValue (关联MJNewValueFromOldValue_Block) + mj_getNewValueFromObject (delegate方法 + 自己和父类关联block)
mj_setupReplacedKeyFromPropertyName/121 ((关联block + removeAllObjects))
mj_setupObjectClassInArray: -> mj_setupBlockReturnValue:key: (关联block + removeAllObjects)
.m --
+load:,+dictForKey: (缓存Dict: replacedKeyFromPropertyName/121Dict_,newValueFromOldValueDict_,objectClassInArrayDict_,cachedPropertiesDict_)
propertyKey: (2delegate方法 + 所有父类MJReplacedKeyFromPropertyName121_Block + replacedKeyFromPropertyNameDict_) -- 将属性名换为其他key去字典中取值
propertyObjectClassInArray: (delegate方法 + 所有父类的 objectClassInArrayDict_)
--mj_enumerateProperties:
-->properties-- cachedPropertiesDict_缓存,mj_enumerateClasses(enumeration回调自己和父类 + class_copyPropertyList,遍历 - (cachedPropertyWithProperty:封装MJProperty),(propertyKey:替换key)setOriginKey:设置propertyKeysDict,(propertyObjectClassInArray数组中需要转换的模型类)setObjectClassInArray:设置objectClassInArrayDict)
--> enumeration回调所有cachedProperties
使用:
(1)简单字典 -> 模型
(2)简单JSON -> 模型
(3)复杂字典 -> 模型 (模型中有模型,模型中有数组中有模型)
(4)简单字典 -> 模型 (key替换,多级映射)
[模型类 mj_objectWithKeyValues:~~]
(5)字典数组 -> 模型数组
[模型类 mj_objectArrayWithKeyValuesArray:~~]
(6)模型 -> 字典
[模型实例 mj_keyValues:~~]
[模型实例 mj_keyValuesWithKeys:~~]
(7)多级映射模型
[模型实例 mj_keyValues:~~]
[模型实例 mj_keyValuesWithIgnoredKeys:@[]]
[模型实例 mj_JSONString]
(8)模型数组 -> 字典数组
[模型类 mj_keyValuesArrayWithObjectArray:]
(9)Core Data && NSCoding
模型 -> 字典