I have an NSArray that contains two types of objects. Lets call them Apple and Orange.
Apple *myApple = [self.searchQueryResults objectAtIndex:indexPath.row];
When I build my cell, I do not know what type in my array is apples or oranges. How can I use a generic identifier type to store an object and then cast accordingly?
You can use isKindOfClass:(Class)aClassto check the type of a class:
isKindOfClass:(Class)aClass
if ([myObject isKindOfClass:[Apple class]]) // do stuff
, , . NSArray , , , , . , -
Apple *myApple = (Apple *)myObject;
, , , , , , , , - .
NSArray.
, , , (, Fruit). , , -, , , , .
, , , - - - , - . , BOOM!
Source: https://habr.com/ru/post/1759624/More articles:zend newbie question - "Adapter not found for" - phpGecko 2 ActiveX Control VCL component in Delphi? - firefoxКаков предпочтительный способ переноса состояния сеанса в ASP.Net? - c#php mysql select all with the same data - phpInno Setup: как создать страницу мастера паролей, только если выбран компонент "X" - passwordsPrevent waving leading to fatal error for large files - phpWhy would you ever use $ _GET in PHP? - httpAnalyzing and Converting 4Test to Perl - PerlHow to get started with directshow? - c ++Stacking components in Java Swing - javaAll Articles