首页 > 代码库 > [IOS 开发] 反射

[IOS 开发] 反射

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

所以我们需要头文件 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 =http://www.mamicode.com/[oneData valueForKey:aName];>

[IOS 开发] 反射