gpt4 book ai didi

ios - 如何在 Objective-C 中将完成处理程序分配给另一个完成处理程序

转载 作者:行者123 更新时间:2023-11-28 19:27:06 27 4
gpt4 key购买 nike

我在完成处理程序中遇到问题。

我有一个方法如下

-(void)authenticationRealmWithCompletion:(void (^)(AuthenticationRealm *authenticationRealm, NSError *error))completion realmId:(NSString *)realmId postDictionary:(NSDictionary *)postDictionary{
//my code
}

现在我声明了一个变量如下

typedef void(^completionHandler)(AuthenticationRealm *authenticationRealm, NSError *error);

现在我想分配如下

-(void)authenticationRealmWithCompletion:(void (^)(AuthenticationRealm *authenticationRealm, NSError *error))completion realmId:(NSString *)realmId postDictionary:(NSDictionary *)postDictionary{
[completion copy];

//**HERE**..... Error Line
completionHandler(completion);

//my code



}

但是我收到错误,因为 Redefinition of 'completion'

请建议如何将完成处理程序分配给另一个。

最佳答案

要分配完成处理程序,您必须创建属性 完成处理程序。

@property (nonatomic, copy) completionHandler completion;

然后在您的方法中使用以下代码进行分配。

self.completion = completion;

更新

方法也可以定义为

-(void)authenticationRealmWithCompletion:(completionHandler)completion
realmId:(NSString *)realmId
postDictionary:(NSDictionary *)postDictionary{

self.completion = completion;

}

关于ios - 如何在 Objective-C 中将完成处理程序分配给另一个完成处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52075389/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com