views:

34

answers:

1

Hi,

I want to know how to create an object to an interface ie @protocol in Objective-C?

+1  A: 

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.

Vladimir
thanks for the reply,this is what i know but i also need to set that myObject to the MyClass Object? How to do that? Pls do reply
Cathy
Still not clear... May be you can post a code you have problems with or describe your situation in more details?
Vladimir