Search code examples
objective-cswiftstatic-functions

How to call swift static method with escaping closure in objective-c file


I have this static function written in swift that I need to call in objective-c file

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

In swift I would simply call it

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

How should I call it in objective-c file?

EDIT: I suppose it should look something like this?

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

Solution

  • You don't need to create an instance for calling a static method. Try this

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