Brent Simmons wrote about some issues he found in an unnamed open-source Cocoa project. He lists 12 things, and while reading them I realized that you can use the Clang compiler and Faux Pas to avoid most of them:
getSomething
. Drop the get
.”Faux Pas has a rule for this: Unidiomatic accessor naming.
#define SOME_CONSTANT 10
isn’t Cocoa-like. Better is static const NSUInteger PBSSomeConstant = 10;
…”Faux Pas has a rule for this: Macro definition for literal value.
Faux Pas can warn you about classes with no prefix at all (Unprefixed Objective-C class), or about prefixes that are too short or collide with Apple’s framework prefixes: Reserved symbol prefix.
The Clang compiler has the -Wobjc-interface-ivars
warning for this: “declaration of instance variables in the interface is deprecated”.
Faux Pas has a related rule: Category used for “private” declarations.
init
method should return instancetype
and not anything else.”Faux Pas has a rule for this: Constructor return type. It can check both convenience constructors and init methods.
self.whatever
accessors in init
, except when unavoidable …”Faux Pas has a rule for this: Setter invocation in init or dealloc method.
Faux Pas has a rule for this: Recommended compiler warning options. The default configuration also recommends treating warnings as errors (-Werror
).
@import
.”The Clang compiler has the -Wauto-import
warning for this.
removeObserver
, fix it.”Faux Pas has a couple of rules that help you find issues related to this: