The obj variable must have a type that has the corresponding property. If both objects have the same property, one way to achieve this would be to declare the property in a common base class. If a common common class is not suitable for these two types, you can force them to accept a common protocol, for example:
@protocol LatitudeHaving @property (copy) NSNumber* latitude; @end @interface Class1 (AdoptLatitudeHaving) <LatitudeHaving> @end @interface Class2 (AdoptLatitudeHaving) <LatitudeHaving> @end
From there, you will declare obj as id<LatitutdeHaving> , for example:
id<LatitudeHaving> obj; if (condition1) obj = (Class1*)[_fetchedResults objectAtIndex:indexPath.row]; else obj = (Class2*)[_fetchedResults objectAtIndex:indexPath.row]; NSNumber *latitude = obj.latitude;
And that should do it. FWIW, protocols are similar to Java interfaces.
ipmcc
source share