ios - Maybe get name of ObjectType in NSArray? -


i have custom class below:

@interface testobject : nsobject   @property (nonatomic, retain) nsarray<obja *> *obja;   @property (nonatomic, retain) nsstring *status;   @property (nonatomic, retain) nsstring *keyword;   @property (nonatomic, retain) objb *objb; @end 

i want objecttype's name of property obja (which objarea), return nsarray. had name of class of other property include objb. how can in runtime? have function list property , class of them extend(category) nsobject this.

- (nsarray *)propertylist {     class currentclass = [self class];     nsmutablearray *propertylist = [[nsmutablearray alloc] init];     {         unsigned int outcount, i;         objc_property_t *properties = class_copypropertylist(currentclass, &outcount);          (i = 0; < outcount; i++) {             objc_property_t property = properties[i];              nsstring *propertyname = [nsstring stringwithformat:@"%s", property_getname(property)];             [propertylist addobject:propertyname];         }         free(properties);         currentclass = [currentclass superclass];     } while ([currentclass superclass]);      return propertylist; } 

and :

- (class) classofpropertynamed:(nsstring*)keypath {     class class = 0;      unsigned int n = 0;     objc_property_t* properties = class_copypropertylist(self.class, &n);     (unsigned int i=0; i<n; i++) {         objc_property_t* property = properties + i;         nsstring* name = [nsstring stringwithcstring:property_getname(*property) encoding:nsutf8stringencoding];         if (![keypath isequaltostring:name]) continue;          const char* attributes = property_getattributes(*property);         if (attributes[1] == '@') {             nsmutablestring* classname = [nsmutablestring new];             (int j=3; attributes[j] && attributes[j]!='"'; j++)                 [classname appendformat:@"%c", attributes[j]];             class = nsclassfromstring(classname);         }         break;     }     free(properties);      return class; } 

you should set custom object in array call

mycustomobject = [yourarray objectatindex:someindex]; mycustomobject.name // ever want 

or create custom object of type nsarray this: enter image description here this: enter image description here want custom array


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -