简体   繁体   中英

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());

@end

And here is my implementation file:

#import "Test.h"

@implementation Test

- (void)test {
    return;
}

@end

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)
#endif

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 #undef ing the macro is a workaround:

@interface Test : NSObject

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

@end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM