objective c - Similar method in ObjectiveC for 'java.lang.Class.getDeclaredField()' -


this question has answer here:

i reading text file. want check whether there variable declared in class name same text read file.

method in java 'java.lang.class.getdeclaredfield()'. see http://www.tutorialspoint.com/java/lang/class_getdeclaredfield.htm details.

i unable find similar method in objectivec. there any? if no, how can implement same. please give me few tips if idea.

you can check this: /for properties/

yourclass *arrobj=[yourclass new];//your target class wnat check nsstring *propertyname=@"samllarray";//this check in class yourclass if([arrobj respondstoselector:nsselectorfromstring(propertyname)]){     nslog(@"yes, exists"); } else{     nslog(@"no, not exists"); } 

edit:/for ivars/

- (nsmutablearray *)getallpropertyofclass:(class)aclass {     nsmutablearray *marray=[nsmutablearray new];     unsigned int outcount;     ivar *ivars = class_copyivarlist([aclass class], &outcount); //class_copypropertylist([aclass class], &outcount);      for(unsigned int = 0; < outcount; i++) {         ivar ivar = ivars[i];         const char *propname = ivar_getname(ivar);         if(propname) {             nsstring *propertyname = [nsstring stringwithutf8string:propname];             marray[marray.count]=propertyname;         }     }     free(ivars);     return marray; } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -