I have a class Topic and Group which both have a variable called ‘name’, so I am trying to combine these two if statements into one:
if ([((RKMappableObjectTableItem *) _item).object isKindOfClass:[Group class]]){
Group * group = (Group *)(((RKMappableObjectTableItem *) self.object).object);
//blah
} else if ([((RKMappableObjectTableItem *) _item).object isKindOfClass:[Topic class]]){
Topic * topic = (Topic *)(((RKMappableObjectTableItem *) self.object).object);
//blah
}
I tried
id group = (((RKMappableObjectTableItem *) self.object).object);
but when I tried group.name, it gives me:
property name not found on object of type id
In Objective-C, properties do undergo a stricter type checking at compile time.
You might want to try:
What you do in this case is not using the property mechanism and sending a message to the object. This allow you to fully exploit the dynamic nature of Objective-C.
In this case, you will get a warning, but if you can stand it, it should work fine.