简体   繁体   English

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

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

I had implemented static library which is written in Objective C language, in new Swift Project.我已经在新的 Swift 项目中实现了用 Objective C 语言编写的静态库。 Everything is fine and I can call a class method and instance method in swift code block successfully.一切都很好,我可以在 swift 代码块中成功调用类方法和实例方法。 But when I try to call a method which is return protocol, I get an error.但是当我尝试调用返回协议的方法时,出现错误。 I have not been calling successfully below method in swift code.我没有在 swift 代码中成功调用下面的方法。

Anyone know how can I call this method in Swift.任何人都知道我如何在 Swift 中调用这个方法。

Static library which is written with Objective C用 Objective C 编写的静态库所有方法都在这里

I can not call a method which name is getScreenManager.我无法调用名称为 getScreenManager 的方法。 Also, Xcode is not showing hint for this method in Swift.此外,Xcode 没有在 Swift 中显示此方法的提示。 在此处输入图片说明

IScreenManager is below. 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;

if you are using swift 3 or later, then try for a method screenManager as there are lot of naming convention changes in swift 3. And due to this objective-c function calling from swift also affects.如果您使用的是 swift 3 或更高版本,那么请尝试使用 screenManager 方法,因为 swift 3 中有很多命名约定更改。并且由于从 swift 调用的这个 Objective-c 函数也会影响。

Click here to read more 点击这里阅读更多

i found solution.我找到了解决方案。 i think, this is a kind of Xcode GM bug.我认为,这是一种 Xcode GM 错误。 Because i did now how to call this method and i expected Xcode will show hint just like other method.. When i write below code section, Xcode not fired error and build and run successfully.因为我现在做了如何调用这个方法,我希望 Xcode 会像其他方法一样显示提示。 Now i am downloading Xcode 9. Thank all for fast response.现在我正在下载 Xcode 9。感谢大家的快速响应。

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

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

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