Return protocol

Objective-C protocol is similar with interface of Java.
In Java, we can return interface(Actually return object is instance which are implemented interface)
How about Objective-C? We can’t just
Use id identifier in this case.

Let’s go sample.

Objective-C Sample

Protocol

@protocol TestProtocol
-(void)helloWorld;
@end

Implementation(Header)

@interface ProtocolImpl : NSObject<TestProtocol>
@end

Implementation(Source)

@implementation ProtocolImpl

-(void)helloWorld {
    NSLog(@"Hello World!");
}

@end

Factory Example(Return id)

-(id<TestProtocol>)getProtocol {
    return [ProtocolImpl alloc] init];
}