简体   繁体   中英

Accessing Objective-C block from Swift

I have this Objective-C code in FileManagerHelper:

+(void)getMyVideoObject:(NSString *)videoId completion:(void (^)(MyVideoObject *myVideoObject, NSError *error)) completionBlock
{

}

For calling from Objective-C:

 [FileManagerHelper getMyVideoObject:videoId completion:^(MyVideoObject *myVideoObject, NSError *error) {

}];

But how do I call this getMyVideoObject from Swift?

FileManagerHelper.getMyVideoObject( .....?

1) Add into your bridging header (-Bridging-Header.h file generated when you add .swift file to Objective-C project)

#import "FileManagerHelper.h"

2) In swift code use the following call

FileManagerHelper.getMyVideoObject("id") { (video, error) in

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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