简体   繁体   中英

How to set a object to an interface in Objective-C?

我想知道如何在Objective-C中为接口(即@protocol)创建对象?

It is not very clear what do you want to get.

If you want to define a class that conforms to a protocol you write:

    @interface MyClass: ParentClass <MyProtocol1, MyProtocol2,...>

If you want to define an object that must be an instance of some class that confirms to a protocol you can write:

   id<MyProtocol> myObject;

If you want to obtain Protocol object by name you can use

Protocol *objc_getProtocol(const char *name)

function. I don't know if you can create Protocol in run-time though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM