Specific Class type parameter in Objective-C

后端 未结 4 1449
[愿得一人]
[愿得一人] 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 18:55

    You can ensure using a protocol check:

    - (id)initWithVehicle:(id)aVehicle;
    ...
    }
    

    Declaring an object as id tells the compiler that you don't care what type the object is, but you do care that it conforms to the specified VehicleProtocol protocol**.

提交回复
热议问题