1234567891011121314151617181920212223242526272829303132 |
- //
- // NSObject+ASToDictionary.m
- // ACSION
- //
- // Created by sunyue on 2019/4/24.
- // Copyright © 2019 acsion. All rights reserved.
- //
- #import "NSObject+ASToDictionary.h"
- @implementation NSObject (ASToDictionary)
- - (NSDictionary *)modelToDictionary
- {
- NSMutableDictionary *props = [NSMutableDictionary dictionary];
- unsigned int outCount, i;
- objc_property_t *properties = class_copyPropertyList([self class], &outCount);
-
- for (i = 0; i<outCount; i++)
- {
- objc_property_t property = properties[i];
- const char* char_f =property_getName(property);
- NSString *propertyName = [NSString stringWithUTF8String:char_f];
- id propertyValue = [self valueForKey:(NSString *)propertyName];
- if (propertyValue) [props setObject:propertyValue forKey:propertyName];
-
- }
-
- free(properties);
- return props;
- }
- @end
|