Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 357
GreenSaguaro Avatar asked Feb 28 '12 12:02

GreenSaguaro


1 Answers

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.

like image 99
Thomas Zoechling Avatar answered Sep 20 '22 19:09

Thomas Zoechling