Name of Swift class when exposed to Objective-C code does not respect the @objc renaming

前端 未结 2 1595
醉梦人生
醉梦人生 2021-02-07 04:39

Given a declaration of a Swift class like

@objc(NSFoo) public class Foo {
   public func bar() -> () {}
}

I would expect, from my reading of

2条回答
  •  Happy的楠姐
    2021-02-07 05:19

    Currently (in XCode8) this seems to have been addressed.

    Defined in XYZLogger.h and XYZLogger.m

    NS_ASSUME_NONNULL_BEGIN
    
    NS_SWIFT_NAME(Logger)
    @interface XYZLogger : NSObject
    
    + (void)verbose:(NSString *)logString;
    + (void)debug:(NSString *)logString;
    + (void)info:(NSString *)logString;
    + (void)warn:(NSString *)logString;
    + (void)error:(NSString *)logString;
    
    @end
    
    NS_ASSUME_NONNULL_END
    

    Used in objc like this:

    [XYZLogger debug:@"Hi from objective C"];
    

    Used in Swift like this:

    Logger.debug("Hi from swift");
    

提交回复
热议问题