Reputation: 1123
I'm working on a design issue for my iOS app regarding protocols. Now I understand the usage, and when a protocol is required, and I also understand that they are analogous to interfaces in C# and Java.
Can you call methods through the protocol itself? For example, in C# I can do the following:
public interface IInterface
{
void SomeMethod();
void SomeOtherMethod();
}
public class AClass : IInterface
{
public void SomeMethod()
{
//Do something
}
public void SomeOtherMethod()
{
//Do something
}
}
public class Program
{
public void Main()
{
IInterface i = new AClass();
i.SomeMethod();
}
}
Is this possible in Objective-C or am I trying to force a .NET style approach into iOS?
Upvotes: 0
Views: 352
Reputation: 9593
@protocol Protocol
- (void)someFunction;
@end
@interface A <Protocol>
@end
@implementation A
- (void) someFunction
{
....
}
@end
In some other place
id<Protocol> a = [[A alloc] init];
[a someFunction];
[a release];
Upvotes: 4