Here is a snippet of code from my iOS app:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Do you like my hat?" message:@"If so, please help spread the word by rating our app now?" delegate:nil cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Sure!", @"Maybe Later", nil ];
Why are Xcode indentation lines so bloody? Being an old monkey of Perl, Ruby and JavaScript, I would be more inclined to step back from it manually:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Do you like my hat?" message: @"If so, please help spread the word by rating our app now?" delegate: nil cancelButtonTitle: @"No Thanks" otherButtonTitles: @"Sure!", @"Maybe Later", nil ];
Thus, the names and values โโof the parameters are left-aligned and have only one level (4 spaces for me). This uses far less screen real estate, and, less likely, I have to deal with line wraps (which make it completely believable, even more difficult to read) on my MacBook Air.
However, I assume that Apple for some reason prefers the first method, and therefore has such an Xcode indent. Or is there?
So, I have two questions:
- How do you prefer the indent method parameters in Objective-C code?
- How do you configure Xcode to format with your preferred indentation style?
Not trying to start a holy war here; I am more curious that, as a rule, the best methods are among Objective-C programmers, as Xcode helps with these practices, and find out if there is a good reason for the default method that Xcode does.
Update:. Commentary and answers indicate that formatting by default aligns parameters in its columns. I had to remember that before publication, since I, of course, noticed this, and when the longest element does not have a large segment, it can look pretty pretty. But I find that, as a rule, the longest element is indented quite a lot. For instance:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Do you like my hat?" message:@"If so, please help spread the word by rating our app now?" delegate:nil cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Sure!", @"Maybe Later", nil ];
Why? Even if I wanted them to be aligned with colons (and I often manually formatted them for this), it seems silly to backtrack from them so much. Why does he insist on indentation to the level of the colon? Why not only one level of indentation, but the closing bracket is pushed out to show the end of the โblockโ of the indentation? For instance:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Do you like my hat?" message:@"If so, please help spread the word by rating our app now?" delegate:nil cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Sure!", @"Maybe Later", nil ];
Looks like this is a better default than google style guideline length recommendation , no?
Is there a way to configure Xcode to format the parameters this way?