runtime提示三

來源:互聯網
上載者:User

runtime反射屬性列表:

把反射屬性的用法說完。。。

IOS網路請求大家應該很不陌生了把,但有時候我們需要向伺服器傳遞的資料比較多,這個時候,也是我們runtime發揮的時候了。

直接上代碼,童鞋們估計快該罵人了。一個反射屬性,講這麼久。。。 

-(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];        }    }}

上面是兩個方法都是自己封裝的POST網路請求中使用的,基於ASI,這兩個方法的使用,會使得你的網路請求的代碼實現,十分的簡介,高效。

好了童鞋們相信到了這裡,你對runtime反射屬性的用法已經瞭解的差不多了,有問題,歡迎大家留言。多多提寶貴意見。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.