implicit_knowledge
implicit_knowledge

Reputation: 591

@interface and @implementation in same file (no header file, Xcode unit test template)

Xcode generates this template code for a new Objective-C test case. Why does it not generate a header file and puts the @interface in the implementation file?

#import <XCTest/XCTest.h>

@interface BYObjCTest : XCTestCase

@end

@implementation BYObjCTest

// test methods

@end

How is this construct called? Is this a private class? Test cases are generally not needed to be called from outside of user code, is this the reason this is generated this way?

Upvotes: 0

Views: 474

Answers (1)

Florian Burel
Florian Burel

Reputation: 3456

It's ok to have the interface ClassName : Superclass block (called the class declaration block) in a .m file.

Declaring a class in a Header (.h) file is more common because it's for class that needs be public (class that will be used in other class), but if your class is not meant to be used in outside of the .m file, then it's ok to have the declaration and implementation in the same .m or .mm file.

In the test of TestClass for example, they are not used anywhere else,so no need for a header.

Other language would call those private class. Well private class in objC have no .h file :)

Upvotes: 3

Related Questions