Objective-C: @class Directive before @interface?

前端 未结 4 1729
星月不相逢
星月不相逢 2020-11-28 20:08

What is the difference between these two class declarations? I don\'t understand why @class is utilized here. Thanks.

@class TestClass;

@interface TestCl         


        
4条回答
  •  旧时难觅i
    2020-11-28 20:48

    @class TestClass;
    

    This merely declares "class TestClass will be defined".

    In this case (the one you pasted) this has no effect of whatsoever, so these are the same.

    However, in case you're going to define a protocol that would use your class name (as type of parameters passed to delegate, for example), you will need to declare @class TestClass before the protocol definition, as your class is still not defined.

    In general, if you need to mention your class name before the class definition is made, you will need to issue @class declaration first

提交回复
热议问题