Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see if a class has a property?

Tags:

ios

iphone

I am parsing some xml, and I update the server pretty frequently with new features. So, when I add a new tag or something, my app, which parses the data crashes when I call because the currentElementValue is not part of my class yet. Is there anyway to check if a class has a property, or should I just catch the exception that gets raised?

[a setValue:currentElementValue forKey:elementName];

Thanks

like image 753
Chris Avatar asked Jul 20 '11 16:07

Chris


1 Answers

Very simple:

if (class_getProperty([object class], "propertyName")) {
    // it has that property!
}
like image 138
Jonathan Grynspan Avatar answered Nov 05 '22 00:11

Jonathan Grynspan