A issue I have when it comes to Objective-C is consistency. With iOS I work in bursts, I can go from working 2-3 months daily with the platform, to not touching it for 5-6 months. With those routines you could end up with pretty inconsistent code. Since the language is using header files, has plenty of ways of writing code and with no clear style guide (like PEP8 for Python) I think things are already difficult to begin with.
But I still though my code was pretty unified. Until I tried Objective-Clean.
Objective-Clean is a tool built by a third party developer (non Apple) that generates and makes sure style guides are followed. It is easy to set up and works with both latest XCode and CocoaPods.
But it is not without flaws. Since the validation runs as a custom shell it can be a bit slow. I also noticed a couple of issues with the validation, these are the things I discovered:
Mistreated multiplication sign
My biggest problem is that the validator treats the multiplication sign wrong when used in a math context.
Look at this line:
float imageArea = self.frame.size.width-(margin*2);
Looks fair right? Here the validator returns the error bjClean: There should be a space before the *, but not after
. It is because it handles it as a method signature.
You can see it when you rearrange the code a bit. This passes validation.
float imageArea = self.frame.size.width-(margin *2);
Validation in comments
The validator treats comments as code, you can see this if you would type // Do this + that
with no spaces between math operators as a setting. It is not a big issue, but I would prefer if comments was ignored altogether.
Pragma mark above row collides with method closing row.
This is also a big issue. Sometimes the validator ignores the setting where pragma mark requires num lines above in favor for num empty lines below method closing brace.
-(void) hello {
[self sayHello];
}
# pragma mark Delegate
This line complains that there needs to be 1 empty row below method closing brace, while at the same time I have a 2 empty rows above pragma mark.
Conclusion
With that said, I've already contacted Code Clean (who makes the app) and will update this post with my findings. Issues or not, consistensy is for the win. The $10 the app costs is well worth it and I've already made it a part of my Objective-C toolbelt.
I've also posted my style guide here, for those who are interested.