I had a Swift method with a parameter called module
. I noticed that the [Project]-Swift.h
autogenerated header renamed that parameter to module_
in the Objective-C signature for that method. After some more investigation, it looks like this is happening for C++ keywords:
@objcMembers class SomeClass: NSObject {
func someMethod(init: String) {}
// ↓ These will append an underscore in the header file.
func someMethod(template: String) {}
func someMethod(consteval: String) {}
}
becomes:
SWIFT_CLASS("_TtC9iOSTester9SomeClass")
@interface SomeClass : NSObject
- (void)someMethodWithInit:(NSString * _Nonnull)init;
- (void)someMethodWithTemplate:(NSString * _Nonnull)template_;
- (void)someMethodWithConsteval:(NSString * _Nonnull)consteval_;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end
Is this documented behaviour of the compiler or just some implementation detail? Why would it be necessary?
5