圆括号对optionAction = attempter(option);
行中的typedef做了什么?
是那个演员?
完整代码:
- (id<ISFModalMessageView>)modalMessageWithError:(NSError *)error recoveryAttempter:(SFErrorRecoveryAttempter)attempter
{
if ([self shouldNotifyUserForError:error] && [self typeForError:error] == SFErrorTypeAlert)
{
NSString *title = [self titleForError:error];
NSString *message = [self messageForError:error];
SFAlertMessageView *alert = [[SFAlertMessageView alloc]initWithTitle:title message:message image:nilcancelButton:@"Cancel"];
SFErrorRecoveryOption option = [self recoveryOptionForError:error];
if (option != SFErrorRecoveryOptionUndefiend)
{
NSString *optionTitle = [self titleForRecoveryOptionOfError:error];
SFModalMessageAction optionAction = nil;
if (attempter) {
optionAction = attempter(option); // This Part
}
if (optionTitle.notEmpty && optionAction) {
[alert addActionButtonWithTitle:optionTitle action:optionAction];
}
}
return alert;
}
return nil;
}
SFErrorRecoveryOption:
typedef NS_ENUM(NSUInteger, SFErrorRecoveryOption) {
SFErrorRecoveryOptionUndefiend = 0,
SFErrorRecoveryOptionTryAgain,
SFErrorRecoveryOptionReport,
SFErrorRecoveryOptionSignIn,
SFErrorRecoveryOptionSignUp,
SFErrorRecoveryOptionReset,
SFErrorRecoveryOptionSignInFacebook,
};
SFModalMessageAction:
typedef void (^ SFModalMessageAction)() ;
SFErrorRecoveryAttempter:
typedef SFModalMessageAction (^ SFErrorRecoveryAttempter)(SFErrorRecoveryOption option);
答案 0 :(得分:3)
很可能SFErrorRecoveryAttempter是对某些block type的类型定义并且有问题的行
attempter(option);
只是调用作为参数传递给您的方法的块。请注意,调用nil块将导致异常,因此添加了if (attempter)
检查