繁体   English   中英

如何在 Swift 语言中调用 Objective C 方法(即返回协议)

[英]How to call Objective C method(which is the return protocol) in Swift Language

我已经在新的 Swift 项目中实现了用 Objective C 语言编写的静态库。 一切都很好,我可以在 swift 代码块中成功调用类方法和实例方法。 但是当我尝试调用返回协议的方法时,出现错误。 我没有在 swift 代码中成功调用下面的方法。

任何人都知道我如何在 Swift 中调用这个方法。

用 Objective C 编写的静态库所有方法都在这里

我无法调用名称为 getScreenManager 的方法。 此外,Xcode 没有在 Swift 中显示此方法的提示。 在此处输入图片说明

IScreenManager 在下面。

 @protocol IScreenManager <NSObject>

@property (weak, nonatomic) id<ScreenManagerDelegate> delegate;
@property (strong, nonatomic) NSDictionary *transitionDictionary;
@property (strong, nonatomic) NSArray *loadingImages;
@property CGFloat loadingAnimationDuration;
@property CGFloat loadingBackgroundAlpha;

- (void)showViewsWithObject:(id)object withMessage:(Response *)message;
- (void)enableScreen;
- (void)disableScreenWillShowLoadingView:(BOOL)willShow;
- (int)getActiveViewId;

- (void)applicationWillEnterForeground;
- (void)applicationDidEnterForeground;
- (void)applicationDidEnterBackground;

如果您使用的是 swift 3 或更高版本,那么请尝试使用 screenManager 方法,因为 swift 3 中有很多命名约定更改。并且由于从 swift 调用的这个 Objective-c 函数也会影响。

点击这里阅读更多

我找到了解决方案。 我认为,这是一种 Xcode GM 错误。 因为我现在做了如何调用这个方法,我希望 Xcode 会像其他方法一样显示提示。 现在我正在下载 Xcode 9。感谢大家的快速响应。

 override func getScreenManager() -> IScreenManager! {
    return MultiLayerScreenManager();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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