Search code examples
xcodecocoaxcode4

Why Does Xcode 4.3 Put @interface ClassName() in Implementation File?


I created a class in Xcode 4.3, and it created the header and implementation files with @interface and @implementation in the correct locations, but there is also an @interface in the implementation file like this:

@interface MyClassName ()

@end

Why does Xcode put that in the implementation file and what is it for?

Thanks, Kurz


Solution

  • Xcode automatically creates a class extension, which allows you to implement "private" methods.
    Class extensions are unnamed categories and have been introduced with Objective-C 2.0.

    One advantage of class extensions is, that the compiler will warn you, if you forget to implement one of the methods declared in the anonymous interface.