将完成块从快速传递到目标

问题描述 投票:0回答:1

[试图从快速代码中获取完成块,但看起来我做错了。

我想为我的快速视图控制器BMPSSecurityQuestionViewController复制的我的objC代码

我只需要在完成块中返回BoolBMError

正常工作的代码:

BMPSAccountManagementViewController *changeVC = [[BMPSAccountManagementViewController alloc] initWithFormlyData:formlyJSON afterUpdatingProfile:completion];

@implementation BMPSAccountManagementViewController

- (instancetype)initWithFormlyData:(NSDictionary *)json afterUpdatingProfile:(void (^)(BOOL, BMErrors *))completion {
    self = [super initWithFormlyData:json];
    if (self) {
        self.updateCompletion = completion;
    }
    return self;
}

我做错的代码:

changeVC.changeSecurityQuestionDelegate = [[BMPSUpdateSecurityQuestionViewModel alloc] init completionData:completion];

我尝试像objc函数一样复制的快速代码:

@objc public class BMPSSecurityQuestionViewController {

    var completionData: ((Bool, BMErrors?) -> Void)?

    public required init?(coder aDecoder: NSCoder) {
        fatalError("Not implemented")
    }

    @objc public init(completionData completion: ((Bool, BMErrors?) -> Void)?) {
        super.init(nibName: nil, bundle: nil)
        self.completionData = completion
    }

    public func verifySuccess() {

        //self.completionData 
        // here I want to set completion data but I don't know how to do it
    }

}
objective-c swift closures objective-c-blocks
1个回答
0
投票

您可以使用以下代码初始化BMPSSecurityQuestionViewController.completionData

self.completionData = { boolValue, errors in
    //This is how you can use boolValue and errors
    if boolValue {
        if let errors = errors {
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.