關於RunTime執行時的小知識
1.class_copyPropertyList與class_copyIvarList區別
class_copyPropertyList 僅僅獲取屬性列表
class_copyIvarList 返回類的所有屬性和變數(包括大括號中申請的變數)
實際應用
1.給分類動態繫結屬性
objc_setAssociatedObject(self, &target_key, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
2.方法的交換
class_replaceMethod(selfClass, cusSEL, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
3.字典轉模型
class_copyPropertyList([selfclass], &outCount);
4.獲取所有的私有屬性和方法
class_copyPropertyList([selfclass], &outCount);
5、對私有屬性修改
(一些封裝起來的類 並沒有在.h檔案中提供屬性 你可以根據class_copyPropertyList([selfclass], &outCount);獲取其中的屬性,再根據valueforkey: 取得 然後可以進行修改 )
6.快速歸檔解檔
7.修改方法