What is the difference between these two class declarations? I don’t understand why @class is utilized here. Thanks.
@class TestClass;
@interface TestClass: UIView {
UIImage *image1;
UIImage *image2;
}
and
@interface TestClass: UIView {
UIImage *image1;
UIImage *image2;
}
@classexists to break circular dependencies. Say you have classes A and B.Chicken; meet Egg. This can never compile because A’s interface depends on B being defined and vice-versa.
Thus, it can be fixed by using
@class:@classeffectively tells the compiler that such a class exists somewhere and, thus, pointers declared to point to instances of said class are perfectly valid. However, you couldn’t call a method on an instance reference whose type is only defined as an@classbecause there is no additional metadata available to the compiler (I can’t remember if it reverts the call site to being evaluated as a call throughidor not).In your example, the
@classis harmless, but entirely unnecessary.