首页 > 解决方案 > 如何在objective-c文件中调用带有转义闭包的swift静态方法

问题描述

我有这个用swift编写的静态函数,我需要在objective-c文件中调用

static func downloadVideo(url: String, onResult: @escaping(String?) -> ()){
    //some code
    onResult("done")
}

迅速我会简单地称之为

Service.downloadVideo(url: "url") { (string) in
    print(string)
}

我应该如何在objective-c文件中调用它?

编辑:我想它应该看起来像这样?

[[Service new] downloadVideo:@"url" onResult:^{
    NSLog(@"success")
}];

标签: objective-cswiftstatic-functions

解决方案


您不需要创建实例来调用静态方法。尝试这个

[Service downloadVideo:@"url" onResult:^{
    NSLog(@"success")
}];

推荐阅读