为什么我在执行委托以将值从子 swift class 传递给父 objective C class 时出错?

Why am I getting error to implement delegate to pass value from a child swift class to a parent objective C class?

我试图将值从 swift class 传递到 objective C class,但出现错误。错误是

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ MainViewController childViewControllerResponseWithAsset:]: unrecognized selector sent to instance 0x7f969a133c00"

ChildViewController swift class:

@objc protocol ChildViewControllerDelegate
{
func childViewControllerResponse(asset:AVAsset)
}

class ChildViewController:UIViewController
{
@objc var delegate: ChildViewControllerDelegate?
@objc var asset:AVAsset!

@objc func apply() {
self.delegate?.childViewControllerResponse(asset: self.Video())

//dismiss view
self.navigationController?.popViewController(animated: false)
}

}

MainViewController objective C class:

#import "Project-Swift.h"
@interface MainViewController()<ChildViewControllerDelegate>
{

-(IBAction)ButtonPressed:(UIButton *)sender{

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
 ChildViewController *vc = (ChildViewController*)[storyboard instantiateViewControllerWithIdentifier:@"ChildViewController"];
 AVAsset *asset = self.originalVideoAsset;
 vc.asset = asset;
 vc.delegate = self;
 [self.navigationController pushViewController:vc animated:YES];

 }

 // Define Delegate Method
 -(void)childViewControllerResponse:(AVAsset*)asset
 {
 self.originalVideoAsset = asset;
 }

}

我将如何解决这个问题或者我做错了什么?

Swift方法childViewControllerResponse变成Objective-C方法childViewControllerResponseWithAsset。这就是 Swift-to-ObjC 转换的工作原理。因此,您应该将 Objective-C 方法重命名为:

 -(void)childViewControllerResponseWithAsset:(AVAsset*)asset
 {
    self.originalVideoAsset = asset;
 }

或者,您可以将 @objc 属性应用于 Swift 方法,并指定您想要的名称:

@objc(childViewControllerResponse)
func childViewControllerResponse(asset:AVAsset)