I have some code that I've included in a project I want to release. Here is one such block:
NSString *path = nil;
if (delegate && [delegate respondsToSelector:@selector(toolbarAssociatedXibName:)]) {
path = [delegate toolbarAssociatedXibName:_toolbar];
if (![[NSBundle mainBundle] pathForResource:path ofType:@"nib"]) {
IFLog(@"Delegate responded with an invalid value (%@) for `toolbarAssociatedXibName:`. Attempting default value (%@).", path, _identifier);
path = _identifier;
}
} else {
path = _identifier;
}
The equivalent pseudocode:
Variable declaration (set to null value)
If there is an option to set the variable to a custom value
Set it to that custom value
If the value is not valid
Log the error
Set the value to a specified default
Otherwise
Set the value to a specified default
Is it possible to shorten/compact this block of code? I have also tried combining this block into a single line of code, ending up with this:
(delegate && [delegate respondsToSelector:@selector(toolbarAssociatedXibName:)] ? !![[NSBundle mainBundle] pathForResource:[delegate toolbarAssociatedXibName:_toolbar] ofType:@"nib"] ? path = [delegate toolbarAssociatedXibName:_toolbar] : IFLog(@"Delegate responded with an invalid value (%@) for `toolbarAssociatedXibName:`. Attempting default value (%@).", [delegate toolbarAssociatedXibName:_toolbar], _identifier), path = _identifier : path = _identifier);
That does absolutely nothing for readability. Any suggestions?