Skip to content

CurrentMobile/objective-c-style-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

ios-style-guide

The MobileX Labs style guide for Objective-C/iOS development.

Send in any improvements as pull requests and/or issues!

  • Favor delegates over blocks for view elements.
  • Put the space before the asterix (except for constants). e.g.
NSString *myString;

Not:

NSString* myString;
// or
NSString * myString;
  • Put commas between property attributes. E.g.
@property (readonly, assign, nonatomic) MXLPullDownViewState viewState;
  • Define all properties as readonly in the header, unless external readwrite access is required.
  • Provide multi-line comment before each method definition. It should explain the method, then each parameter, then any returned result. Use the plugin VVDocumenter to automatically build this. E.g.
/**
 *  Calculates whether the the vertical distance from the top of
 *  the pulldown is significant enough to result in the cell
 *  being redrawn.
 * 
 *  @param offset The vertical distance in points to offset the content.
 *  @return A BOOL to indicate whether the cell should update, based on top offset.
 */
- (BOOL)shouldSetContentViewOffsetFromTop:(CGFloat)offset;
  • Structure of constant names shuld be: kMXLClassNameConstantName. E.g.
const CGFloat kMXLPullDownViewTabHeightDefault = 10;
  • When setting float values, always append "f". E.g.:
CGFloat myFloat = 20.0f;

Not

CGFloat myFloat = 20;
  • Put a space between the method scope (+/-) and return value. e.g.
- (void)myMethod;
  • Use NS_ENUM for declaring typedefs. Read here.
  • Typedef items should be structure: MXLTypeDefNameOptionName, even if it doesn't read as well. For example:
typedef NS_ENUM(NSUInteger, MXLAppSwitcherStyle) {
    MXLAppSwitcherStyleOpen,
    MXLAppSwitcherStyleClosed
};

Not:

typedef NS_ENUM(NSUInteger, MXLAppSwitcherStyle) {
    MXLAppSwitcherOpenStyle,
    MXLAppSwitcherClosedStyle
};
  • Favor dot-syntax over bracket-based message passing.
  • All methods should be defined somewhere. Either publicly in the header, or privately as an interface extension in the .m file. The definition of the method is where the documenting comment should be located.

About

The MobileX Labs style guide for Objective-C/iOS development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages