码迷,mamicode.com
首页 > 移动开发 > 详细

[IOS 开发] 反射

时间:2015-01-08 11:20:16      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

首先我们要知道,这使用的是运行时的反射机制

所以我们需要头文件 runtime.h

+(BOOL)checkoutOneTabByName:(NSString*)oneName
{
    //openDB
    FMDatabase *db = [DatabaseOperation openDataBase];
    
    NSArray *array = [DatabaseOperation queryTable:oneName QueryString:[NSString stringWithFormat:@"select * from %@",oneName] DB:db];
    
    for (id oneData in array) {
        
        unsigned int propertyCount =0;
        
        objc_property_t *FPAddress =class_copyPropertyList([oneData class], &propertyCount);
        
        for (int i =0; i<propertyCount; i++) {
            
            objc_property_t *aProp =FPAddress+i;
            
            NSString *aName =[NSString stringWithUTF8String:property_getName(*aProp)];
            
            NSObject *aValue =[oneData valueForKey:aName];
            
            NSLog(@"%@,,,%@",aName,aValue);
        }
        NSLog(@"( * ^ __ * ^ ) %@ part print success",[oneData class]);
    }
    
    //关闭数据库
    [DatabaseOperation closeDataBase:db];
    
    return YES;
}


[IOS 开发] 反射

标签:

原文地址:http://blog.csdn.net/u010130947/article/details/42521669

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!