Runtime Tips 3

Source: Internet
Author: User

Runtime reflection attribute list:

Describe the usage of reflection attributes...

There should be no stranger to IOS network requests, but sometimes we need to transmit a lot of data to the server. This is also the time for us to use runtime.

Directly go to the Code, and the kids shoes are estimated to be swearing soon. A reflection attribute, for so long...

-(void)createPostDateWithDic{    NSArray * arr = [self.requestDictionary allKeys];    for (int i = 0; i < arr.count; i ++) {        if ([self.requestDictionary objectForKey:[arr objectAtIndex:i]] != nil) {            [self.mainRequest setPostValue:[self.requestDictionary objectForKey:[arr objectAtIndex:i]] forKey:[arr objectAtIndex:i]];        }    };}-(void)createPostDateWithModel{    unsigned int outCount, i;    objc_property_t *properties = class_copyPropertyList([self.requestModel class], &outCount);    for (i=0; i<outCount; i++) {        objc_property_t property = properties[i];        NSString * key = [[NSString alloc]initWithCString:property_getName(property)  encoding:NSUTF8StringEncoding];        id value = [self.requestModel valueForKey:key];        if (value != nil) {            [self.mainRequest setPostValue:value forKey:key];        }    }}

The above two methods are used in self-encapsulated POST network requests. Based on ASI, the use of these two methods will make the code implementation of your network request very brief and efficient.

Now, I believe that you have learned about the usage of the runtime reflection attribute. If you have any questions, please leave a message. Provide more valuable comments.

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.