首页 > 其他 > 详细

runtime使用技巧三

时间:2014-05-19 09:33:58      阅读:317      评论:0      收藏:0      [点我收藏+]

runtime反射属性列表:

把反射属性的用法说完。。。

IOS网络请求大家应该很不陌生了把,但有时候我们需要向服务器传递的数据比较多,这个时候,也是我们runtime发挥的时候了。

直接上代码,童鞋们估计快该骂人了。一个反射属性,讲这么久。。。 

bubuko.com,布布扣
-(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];
        }
    }
}
bubuko.com,布布扣

上面是两个方法都是自己封装的POST网络请求中使用的,基于ASI,这两个方法的使用,会使得你的网络请求的代码实现,十分的简介,高效。

好了童鞋们相信到了这里,你对runtime反射属性的用法已经了解的差不多了,有问题,欢迎大家留言。多多提宝贵意见。

runtime使用技巧三,布布扣,bubuko.com

runtime使用技巧三

原文:http://www.cnblogs.com/ggxbq/p/3732062.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!