![](/img/trans.png)
[英]How to call a method through the object created by interface in Objective-C
[英]How to set a object to an interface in Objective-C?
我想知道如何在Objective-C中為接口(即@protocol)創建對象?
您還不確定要獲得什么。
如果要定義符合協議的類,請編寫:
@interface MyClass: ParentClass <MyProtocol1, MyProtocol2,...>
如果要定義一個對象,該對象必須是某個可以確認協議的類的實例,則可以編寫:
id<MyProtocol> myObject;
如果要按名稱獲取協議對象,可以使用
Protocol *objc_getProtocol(const char *name)
功能。 我不知道您是否可以在運行時創建協議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.