I am trying to understand this objc code, so I'd like to get the Swift code conversion:
- (void)transmitMultipleCommands:(NSArray<LTOBD2Command*>*)commands completionHandler:(nullable LTOBD2MultipleCommandsResponseHandler)handler {
if ( !commands.count )
{
return;
}
[commands enumerateObjectsUsingBlock:^(LTOBD2Command * _Nonnull command, NSUInteger idx, BOOL * _Nonnull stop) {
LTOBD2CommandResponseHandler commandHandler = ( idx < commands.count - 1 ) ? nil : ^(LTOBD2Command* command ){
handler( commands );
};
[self transmitCommand:command responseHandler:commandHandler];
}];
}
I don't understand this syntax:
LTOBD2CommandResponseHandler commandHandler = ( idx < commands.count - 1 ) ? nil : ^(LTOBD2Command* command ){
handler( commands );
};
What is the goal ?
Thank you in advance for your help.