Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 + (NSArray *)findValuesforKey:(NSString *)key; 方法 查询 某个键 对应表中的… #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wuyaomin
Copy link

…所有值的数组

@FQDEVER
Copy link

FQDEVER commented Apr 25, 2018

/**

  • 获取该类的所有属性
    */
  • (NSDictionary *)getPropertys
    {
    NSMutableArray *proNames = [NSMutableArray array];
    NSMutableArray *proTypes = [NSMutableArray array];
    NSArray *theTransients = [[self class] transients];

    unsigned int outCount, i;
    Class class = [self class];

    while (class != [JKDBModel class]) {

      objc_property_t *properties = class_copyPropertyList(class, &outCount);
      for (i = 0; i < outCount; i++) {
          objc_property_t property = properties[i];
          //获取属性名
          NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
          if ([theTransients containsObject:propertyName]) {
              continue;
          }
          [proNames addObject:propertyName];
          //获取属性类型等参数
          NSString *propertyType = [NSString stringWithCString: property_getAttributes(property) encoding:NSUTF8StringEncoding];
          /*
           各种符号对应类型,部分类型在新版SDK中有所变化,如long 和long long
           c char         C unsigned char
           i int          I unsigned int
           l long         L unsigned long
           s short        S unsigned short
           d double       D unsigned double
           f float        F unsigned float
           q long long    Q unsigned long long
           B BOOL
           @ 对象类型 //指针 对象类型 如NSString 是@“NSString”
           
           
           64位下long 和long long 都是Tq
           SQLite 默认支持五种数据类型TEXT、INTEGER、REAL、BLOB、NULL
           因为在项目中用的类型不多,故只考虑了少数类型
           */
          if ([propertyType hasPrefix:@"T@\"NSString\""]) {
              [proTypes addObject:SQLTEXT];
          } else if ([propertyType hasPrefix:@"T@\"NSData\""]) {
              [proTypes addObject:SQLBLOB];
          } else if ([propertyType hasPrefix:@"Ti"]||[propertyType hasPrefix:@"TI"]||[propertyType hasPrefix:@"Ts"]||[propertyType hasPrefix:@"TS"]||[propertyType hasPrefix:@"TB"]||[propertyType hasPrefix:@"Tq"]||[propertyType hasPrefix:@"TQ"]) {
              [proTypes addObject:SQLINTEGER];
          } else {
              [proTypes addObject:SQLREAL];
          }
          
      }
      free(properties);
      
      class = [class superclass];
    

    }

    return [NSDictionary dictionaryWithObjectsAndKeys:proNames,@"name",proTypes,@"type",nil];
    }

查询所有属性.包含父类的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants