Skip to content

Instantly share code, notes, and snippets.

@sahara-ooga
Last active May 25, 2017 03:29
Show Gist options
  • Save sahara-ooga/a854a8df65d35c998def8e8a2ac370e9 to your computer and use it in GitHub Desktop.
Save sahara-ooga/a854a8df65d35c998def8e8a2ac370e9 to your computer and use it in GitHub Desktop.
プロトコルに準拠したid型の利用
#import "ObjcClass.h"
let objectConformsSomeProtocol = ObjcClass.objectConformsSomeProtocol()
objectConformsSomeProtocol?.doSomething()
#import <Foundation/Foundation.h>
@protocol SomeProtocol
-(void)doSomething;
@end
@interface ObjectConformsSomeProtocol:NSObject<SomeProtocol>
@end
@interface ObjcClass:NSObject
+(id<SomeProtocol>)objectConformsSomeProtocol;
@end
#import "ObjcClass.h"
@implementation ObjectConformsSomeProtocol
-(void)doSomething{
NSLog(@"Do Something.");
}
@end
@implementation ObjcClass
+(id<SomeProtocol>)objectConformsSomeProtocol{
return [ObjectConformsSomeProtocol new];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment