Specific Class type parameter in Objective-C

后端 未结 4 1602
[愿得一人]
[愿得一人] 2021-02-13 18:22

I want to accept a Class object as a parameter to a constructor of one of my classes. It needs to do a lot of custom work with it, and I want to abstract that away from the use

4条回答
  •  耶瑟儿~
    2021-02-13 19:03

    If you want to init dealership with a vehicle (I mean an initialized instance) you should do:

    - (id)initWithCar:(Vehicle *)carClass
    {
        //An extra check (only for DEBUG mode)
        NSAssert([carClass isKindOfClass:[Vehicle class]]);
        ... //carClass is now a Vehicle instance
    }
    

提交回复
热议问题