user3237732 user3237732 - 6 months ago 69
Objective-C Question

NS_SWIFT_NAME base name verify error

I have following code in my header file Test.h:

#import <Foundation/Foundation.h>

@interface Test : NSObject

- (void)test NS_SWIFT_NAME(verify());


And here is my implementation file:

#import "Test.h"

@implementation Test

- (void)test {


Then I try to import this interface to my swift source code, but I get following warning: 'swift_name' attribute has invalid identifier for base name and swift name for this function is still test. Other names like verif, or verify1 work just great.
Any thoughts?


verify is defined as a macro in <usr/include/AssertMacros.h>:

#ifndef verify
    #define verify(assertion) __Verify(assertion)

in terms of another macro __Verify. As a consequence, the compiler preprocesses the definition to (as you can verify with Product -> Perform Action -> Preprocess "Test.m")

- (void)test __attribute__((swift_name("do { if ( __builtin_expect(!(), 0) ) { DebugAssert('?*?*', 0, \"Third Party Client\" \": \" \"\", 0, 0, \"/PathTo/Test.h\", 22, (void*)0); } } while ( 0 )")));

which is definitely not a valid Swift name.

Using a different name would be the easiest solution. Otherwise #undefing the macro is a workaround:

@interface Test : NSObject

#undef verify
- (void)test NS_SWIFT_NAME(verify());