no message
This commit is contained in:
1 parent
de5bd21a43
commit
568ad5c409
262 files changed
+23226
-78
No files matched your search
Executable
+77
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// PNObjectProperty.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 28/12/15.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNObjectProperty.h"
|
||||
#import "objc/runtime.h"
|
||||
|
||||
@implementation PNObjectProperty
|
||||
|
||||
static BOOL property_getTypeString( objc_property_t property, char *buffer )
|
||||
{
|
||||
const char * attrs = property_getAttributes( property );
|
||||
if ( attrs == NULL )
|
||||
return NO;
|
||||
|
||||
const char * e = strchr( attrs, ',' );
|
||||
if ( e == NULL )
|
||||
return NO;
|
||||
|
||||
int len = (int)(e - attrs);
|
||||
memcpy( buffer, attrs, len );
|
||||
buffer[len] = '\0';
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+ (NSDictionary *)propertiesForClass:(Class)PNObjClass
|
||||
{
|
||||
if (PNObjClass == NULL) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSMutableDictionary *results = [NSMutableDictionary dictionary];
|
||||
|
||||
unsigned int outCount, i;
|
||||
objc_property_t *properties = class_copyPropertyList(PNObjClass, &outCount);
|
||||
for (i = 0; i < outCount; i++) {
|
||||
objc_property_t property = properties[i];
|
||||
const char *propName = property_getName(property);
|
||||
if(propName) {
|
||||
//const char *propType = getPropertyType(property);
|
||||
char propType[256];
|
||||
if (!property_getTypeString(property, propType)) {
|
||||
continue;
|
||||
}
|
||||
NSString *propertyName = [NSString stringWithUTF8String:propName];
|
||||
NSString *propertyType = [NSString stringWithUTF8String:propType];
|
||||
|
||||
NSRange range = [propertyType rangeOfString:@"T@\""];
|
||||
NSRange range2 = [propertyType rangeOfString:@"T"];
|
||||
if (range.location != NSNotFound) {
|
||||
NSRange subStrRange = NSMakeRange(range.length, propertyType.length - (range.length + 1));
|
||||
propertyType = [propertyType substringWithRange:subStrRange];
|
||||
}
|
||||
else if (range2.location != NSNotFound) {
|
||||
NSRange subStrRange = NSMakeRange(range2.length, propertyType.length - (range2.length));
|
||||
propertyType = [propertyType substringWithRange:subStrRange];
|
||||
}
|
||||
|
||||
//NSLog(@"Prop type & name: %@ -- %@", propertyType, propertyName);
|
||||
|
||||
[results setObject:propertyType forKey:propertyName];
|
||||
}
|
||||
}
|
||||
free(properties);
|
||||
|
||||
// returning a copy here to make sure the dictionary is immutable
|
||||
return [NSDictionary dictionaryWithDictionary:results];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user