Runtime Tips 1

Source: Internet
Author: User

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

}

}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.