Objective c isKindOfClass missunderstanding?

前端 未结 3 1061
野趣味
野趣味 2020-12-05 18:56

I have following structure of objects:

Animal, Dog and Cat. As You expect Dog and Cat are inherited from Animal.

And I\'ve a farm class:

 @im         


        
3条回答
  •  温柔的废话
    2020-12-05 19:39

    You are missing breaks, that's why your switch isn't working. It should look like this.

    switch (type) {
    
     case CAT:
       return [Cat new];
     break;
     case DOG:
       return [Dog new];
     break;
     default:
       return [Animal new];
     break;
    }
    

提交回复
热议问题