在方法中返回完成处理程序之前如何等待委托完成?

How can I wait for delegate to complete before returning completion handler in method?

我有一个执行操作的方法。

- (void)mutualDeleteDialog:(QBChatDialog *)dialog success:(void (^) ())successBlock failure:(void (^)(NSError *))failureBlock {
  QBChatMessage *deleteMessage = [self generateDeleteDialogMessage:dialog];
  [self sendMessage:deleteMessage success:^{
    [QBChat deleteDialogWithID:dialog.ID delegate:self];
  } failure:^(NSError *error) {
    failureBlock(error);
  }];

deleteDialogWithID 方法调用第三方服务,完成后调用委托方法。当调用此委托方法时,我想 return success/failure 阻止我原始方法的调用者...这可能吗?我该怎么做?

//Delegate Method
- (void)completedWithResult:(QBResult *)result {
  successBlock();
}

如果你能保证一次只有其中一个,你可以在你的class中添加一个属性:

@property (copy) void(^successBlock)();

然后在 mutualDeleteDialog:

self.successBlock = successBlock;

然后在 completedWithResult:

self.successBlock();

这很不寻常。您可能需要重新评估您正在尝试做的事情。可能有更好的方法。