Objective-C: @class Directive before @interface?

前端 未结 4 1726
星月不相逢
星月不相逢 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条回答
  •  囚心锁ツ
    2020-11-28 21:05

    As per Matt's answer there's absolutely no point to the @class declaration in your code. @class forward defines a class so that the compiler subsequently knows what general sort of unit you are referring to. Since Objective-C is pretty much typeless at runtime, that's often all that the compiler actually needs to know — just enough to distinguish the thing from an atomic C value.

    I'm going to take a stab in the dark and say that because the instance variables are declared in the @interface you're looking at some old code. Because it's old code, the @class probably used to be somewhere else (eg, there was a delegate protocol declared in between) and has just ended up harmlessly stranded.

提交回复
热议问题