MJExtension

Tag_3.0.10

<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




模型 -> 字典


跟著MJExtension實現(xiàn)簡單的字典轉(zhuǎn)模型框架

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容