<1> MJExtensionConst
.h ?-- ?宏定義error/log巫糙,一堆斷言严沥,宏定義重寫desc方法(模型轉(zhuǎn)字典打印)蛛勉,extern屬性類型
.m ?-- ?定義常量
<2> MJFoundation
.h? -- ?+isClassFromFoundation:
.m? --? +foundationClasses:剔桨,+isClassFromFoundation:
<3> MJProperty
.h? -- ?+cachedPropertyWithProperty:
.m? -- 2Dict-getters懶加載限匣,
+cachedPropertyWithProperty:?(懶加載_關(guān)聯(lián)對象緩存) -----> setProperty:(_property讥珍,_name历极,_type(cachedTypeWithCode - 封裝MJPropertyType))
setOriginKey:forClass:? --? NSString & NSArray
-->? propertyKeysWithStringKey:(多級映射stu.bag, ?i. 處理替換后的key(如: name.info[1].nameChangedTime)? ? ii. MJPropertyKey)
-->? setPropertyKeys:forClass: + propertyKeysForClass:(設(shè)置propertyKeysDict)
setObjectClassInArray:forClass: + objectClassInArrayForClass(objectClassInArrayDict)
valueForObject: && setValue:forObject:(KVC的一層封裝)
<4> MJPropertyKey
.h? --? keyName,keyType衷佃,valueInObject:
.m? --? valueInObject:(根據(jù)keyType判斷取值趟卸,NSDictionary & NSArray)
<5> MJPropertyType
.h? -- ?+cachedTypeWithCode
.m? --? +cachedTypeWithCode:(有從types_(緩存type)拿出,沒有自創(chuàng)放入) -> 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:(自己和父類回調(diào)enumeration)
.m? -- ?+load:鸭蛙,+dictForKey:(返回黑白名單PropertyNames緩存字典)
mj_setupAllowedPropertyNames:+mj_setupAllowedCodingPropertyNames: + mj_setupIgnoredPropertyNames:+mj_setupIgnoredCodingPropertyNames: -------------> mj_setupBlockReturnValue:key: (關(guān)聯(lián)黑白名單block + removeAllObjects)
mj_totalAllowedPropertyNames:+mj_totalAllowedCodingPropertyNames: +mj_totalIgnoredPropertyNames: + mj_totalIgnoredCodingPropertyNames: -------------> mj_totalObjectsWithSelector:key: (黑白名單dict取摹恨,有返回,沒有娶视,從delegate方法中拿 - 從所有自己和父類的關(guān)聯(lián)對象中拿)
<2> NSObject+MJCoding
.h ?-- ?@protocol MJCoding - mj_allowed/ignoredCodingPropertyNames
mj_decode: + mj_encode: (mj_enumerateProperties:回調(diào)晒哄,黑白名單判定,encode: KVC取值 -> encodeObject:forKey:肪获,decode: decodeObjectForKey -> KVC賦值)
歸檔的實現(xiàn)宏 - 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 (關(guān)聯(lián)error)
mj_referenceReplacedKeyWhenCreatingKeyValues,mj_isReferenceReplacedKeyWhenCreatingKeyValues (所有父類get關(guān)聯(lián)對象)
mj_objectWithKeyValues: context:-> mj_setKeyValues:context:? -> mj_enumerateProperties: ( 黑白名單雌桑,propertyKeysDict中剝洋蔥到value取值喇喉,值過濾,? ? i. 模型屬性 -> 遞歸校坑,ii. objectClass數(shù)組中模型(1. string array -> url array 2. mj_objectArrayWithKeyValuesArray:context: (遞歸)) ?iii. 基礎(chǔ)類型轉(zhuǎn)換?)
mj_keyValuesWithKeys: ignoredKeys: (mj_enumerateProperties: 黑白名單檢測拣技,取值,? i.模型屬性 -> 遞歸耍目,ii. 數(shù)組里面有模型 -> mj_keyValuesArrayWithObjectArray:keys:ignoredKeys: (遞歸)膏斤,iii. NSURL -> absoluteString,
iv.參考delegate方法(if. 枚舉propertyKeysDict中array中propertyKey - (if >=2. 下一個根據(jù)類型創(chuàng)建加入前一個 ?else.只有一個邪驮,直接賦值) ?else. 直接賦值) )
<2> NSObject+MJProperty
.h? -- block: MJPropertiesEnumeration莫辨,MJReplacedKeyFromPropertyName/121,MJObjectClassInArray毅访,MJNewValueFromOldValue
mj_enumerateProperties:
mj_setupNewValueFromOldValue (關(guān)聯(lián)MJNewValueFromOldValue_Block) + mj_getNewValueFromObject (delegate方法 + 自己和父類關(guān)聯(lián)block)
mj_setupReplacedKeyFromPropertyName/121 ((關(guān)聯(lián)block + removeAllObjects))
mj_setupObjectClassInArray: -> mj_setupBlockReturnValue:key: (關(guān)聯(lián)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回調(diào)自己和父類 + class_copyPropertyList守呜,遍歷 - (cachedPropertyWithProperty:封裝MJProperty)型酥,(propertyKey:替換key)setOriginKey:設(shè)置propertyKeysDict山憨,(propertyObjectClassInArray數(shù)組中需要轉(zhuǎn)換的模型類)setObjectClassInArray:設(shè)置objectClassInArrayDict)
-->? enumeration回調(diào)所有cachedProperties
使用:
(1)簡單字典 -> 模型
(2)簡單JSON -> 模型
(3)復(fù)雜字典 -> 模型 (模型中有模型,模型中有數(shù)組中有模型)
(4)簡單字典 -> 模型 (key替換冕末,多級映射)
[模型類 ?mj_objectWithKeyValues:~~]
(5)字典數(shù)組 -> 模型數(shù)組
[模型類 ?mj_objectArrayWithKeyValuesArray:~~]
(6)模型 -> 字典
[模型實例 ?mj_keyValues:~~]
[模型實例 ?mj_keyValuesWithKeys:~~]
(7)多級映射模型
[模型實例 ?mj_keyValues:~~]
[模型實例? mj_keyValuesWithIgnoredKeys:@[]]
[模型實例? mj_JSONString]
(8)模型數(shù)組 -> 字典數(shù)組
[模型類 ?mj_keyValuesArrayWithObjectArray:]
(9)Core Data && NSCoding
模型 -> 字典