Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've found that boliva's solution works fine in the simulator, but on device the fixed length substring causes problems. I have written a more Objective-C-friendly solution to this problem that works on the device. In my version, I convert the C-String of the attributes to an NSString and perform string operations on it to get a substring of just the type description.</p> <pre><code>/* * @returns A string describing the type of the property */ + (NSString *)propertyTypeStringOfProperty:(objc_property_t) property { const char *attr = property_getAttributes(property); NSString *const attributes = [NSString stringWithCString:attr encoding:NSUTF8StringEncoding]; NSRange const typeRangeStart = [attributes rangeOfString:@"T@\""]; // start of type string if (typeRangeStart.location != NSNotFound) { NSString *const typeStringWithQuote = [attributes substringFromIndex:typeRangeStart.location + typeRangeStart.length]; NSRange const typeRangeEnd = [typeStringWithQuote rangeOfString:@"\""]; // end of type string if (typeRangeEnd.location != NSNotFound) { NSString *const typeString = [typeStringWithQuote substringToIndex:typeRangeEnd.location]; return typeString; } } return nil; } /** * @returns (NSString) Dictionary of property name --&gt; type */ + (NSDictionary *)propertyTypeDictionaryOfClass:(Class)klass { NSMutableDictionary *propertyMap = [NSMutableDictionary dictionary]; unsigned int outCount, i; objc_property_t *properties = class_copyPropertyList(klass, &amp;outCount); for(i = 0; i &lt; outCount; i++) { objc_property_t property = properties[i]; const char *propName = property_getName(property); if(propName) { NSString *propertyName = [NSString stringWithCString:propName encoding:NSUTF8StringEncoding]; NSString *propertyType = [self propertyTypeStringOfProperty:property]; [propertyMap setValue:propertyType forKey:propertyName]; } } free(properties); return propertyMap; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload