iPhone Objective-C foreach дизайн

Наша компания (и другие) использует Компоненты Межстраны открытого исходного кода для библиотеки Unicode (ICU), первоначально разработанной Taligent.

Это обрабатывает строки, локали, преобразования, дату/времена, сопоставление, преобразования, и. al.

Запускаются с ICU Userguide

11
задан 1 October 2014 в 23:28
поделиться

2 ответа

You need to test for the class type:

for (Touch *t in touches) {
  if ([t isKindOfClass:[MoveTouch class]]) {
    MoveTouch *mt = (MoveTouch *)t;
    // do what you want with mt
  }
}
40
ответ дан 3 December 2019 в 01:29
поделиться

I'm not an Objective C programmer.

In your case, I think you need to go through your list with that "for (Touch* in touches)" and in the body figure out if that object is either a MoveTouch or a JumpTouch and so forth.

But the idea of polymorphism is that you don't do this. You don't sort 'm out during your loop. The action that you want to perform should be defined in the interface, and each descendant class implements a different implementation for that action. That's what polymorphism is all about.

0
ответ дан 3 December 2019 в 01:29
поделиться