Search code examples
iosobjective-cobjective-c++

Undefine a duplicate interface in Objective-C


Is there a way I can undefine a previously defined interface ? Or is there way I can check if an interface has been defined already.

For some unexplainable reasons I need to define the exact same interfaces in two different files with the exact same names and definitions.

Both these headers can be imported at the same time which leads to duplicate interface defnintion.

What I've tried

#ifndef Test_Sandwich
#define Test_Sandwich
NS_SWIFT_NAME(Test.Sandwich)
@interface Test_Sandwich : NSObject
@end
#endif

But that gives me Expected Identifier errors on ": NSObject"


Solution

  • The error was because I was naming the identifier the same as the interface This worked

    #ifndef Test_Sandwich2
    #define Test_Sandwich2
    NS_SWIFT_NAME(Test.Sandwich)
    @interface Test_Sandwich : NSObject
    @end
    #endif