LoginSignup
3
4

More than 5 years have passed since last update.

備忘録:Objective-C クラスやインスタンスが、指定のプロトコルに適合しているかどうかをチェックする方法

Last updated at Posted at 2014-02-25

以下のメソッドを使えば、あるクラスまたはインスタンスが指定のプロトコルに適合しているかどうかをチェックできる。

+ (BOOL)conformsToProtocol:(Protocol *)protocol;
- (BOOL)conformsToProtocol:(Protocol *)protocol;

サンプル

id obj = ....;

if ( [obj conformsToProtocol:@protocol(FooProtocol)] ) {
  id<FooProtocol> fooObj = obj;
  ...
  ...
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4