Runtime:
I have been switching to ios development for a while, but I have never been able to sort out my knowledge. Today I am sharing my experiences, mainly for the purpose of communication and learning. I hope you can correct me and make progress together, okay. Next, go to the question. Runtime is certainly not unfamiliar to many people (if you are unfamiliar with it, you can choose to learn it. There are many online experts who have already given it). But have we applied what we have learned? I will share some of my experiences in runtime and hope to help you.
Runtime reflection attribute list:
Runtime can reflect the list of runtime class attributes. This is actually very helpful for our development.
One of its usage methods today:
In MVC mode, the encapsulated model contains a large number of entities and attributes. We often encounter model transfer during development. To facilitate development, we need to view the values of each attribute in the model. Runtime helps us solve this problem well. If you don't talk much about it, simply add the code.
-()printAll:(* str == [NSString stringWithFormat:= [str stringByAppendingString:[self printStr:obj Num:= [NSString stringWithFormat:-(NSString *)printStr:(*properties = class_copyPropertyList([obj ], & (outCount == [NSString stringWithFormat:* str =* nullStr == (i=; i<outCount; i++=* key = value == [NSString stringWithFormat:,str,nullStr,key,[self printStr:value Num:key.length + num += [NSString stringWithFormat:-(NSString ** str = ( i = ; i<num; i++= [str stringByAppendingString:
Remember to declare the header file
# Import <objc/runtime. h>
Add the above method to the NSObject category and declare it as global in. pch.
In this way, any id object can call the printAll method to print the output.
The effect is as follows:
014-05-06 17:38:58. 013 LTTest [10011: 90b]
MyTestModle:
{
Name:Dinner
Address:Drinking Water
Model :{
Name:Dinner2
Address: 2
Mymodel :{
Name:Dinner3
Address:Drinking Water3
}
}
}