Skip to content

Latest commit

 

History

History
206 lines (162 loc) · 3.1 KB

File metadata and controls

206 lines (162 loc) · 3.1 KB

Coding Style Rules

This document defines Swift and Objective-C code style rules for this project.

Table of Contents

Swift

The swift code style rules are defined by this set of swiftlint rules

Objective-C

Variable names should use capitalization on all word expect the first, and never '_' ie

Right:

BOOL isFirstTimeReading;
int age;
NSArray *myArray;

Wrong:

BOOL is_first_time_reading;
int Age;
int isFirstTimeReading_ever;

Objective-C Instance variables must be prefixed with _

Right:

@interface Object {
	  BOOL _isFirstTimeReading;
	  int _age;
}

Wrong:

@interface Object {
	  BOOL isFirstTimeReading;
	  int age;
}

Pointer * must be preceded with a space and with no space after ie

Right:

void *pointer;

Wrong:

void * pointer;
void* pointer;
void*pointer;

If, switch, and other keyword that are not function but takes parameter should have a space before ()

Right:

if (a) {
  ...
}
function();

Wrong:

if( a )
if ( a )
if(a)
function ();

Brackets usage

Right:

if (a) {
   ...
}
while (a) {
   ...
}
void function()
{
   ...
}
- (void)functionWithParameter:(BOOL)parameter
{
   ...
}

Wrong:

- (void)function {
   ...
}
if (a)
{
   ...
}

Prefer early return ie:

Prefer:

if (!a)
    return;

Over:

if (a) {
  ...
  ...
}

Objective C code - Don't call multiply the same method.

Right:

NSWindow *window = [self window];
NSRect frame = [window frame];
frame.origin.x = 0;
[window setFrame:frame display:NO];

Wrong:

NSRect frame = [[self window] frame];
frame.origin.x = 0;
[[self window] setFrame:frame display:NO];
objectAtIndex is gone - keep it like this

Right:

NSArray *array;
…filled with lots of stuff
id object = array[index];

Wrong:

NSArray *array;
…filled with lots of stuff
id object = [array objectAtIndex:index];
NSArray literals improve readability - use them

Right:

NSArray *array = @[obj1, obj2, obj3];

Wrong:

NSArray *array = [NSArray arrayWithObjects: obj1, obj2, obj3, nil];

Commit naming

Commit titles should follow a certain template in order to keep a better track of them.

A commit message can be added if needed to explain the purpose of the commit and give more context.

This is how you should title your commits:

filename: Brief description

or

subject: Brief description

Example: Some changes were made to the UPnP integration in order to drop the obsolete iOS 7 support in the VLCNetworkServerBrowserUPnP.m file.

Right:

VLCNetworkServerBrowserUPnP: Remove iOS 7 compatibility code

or

UPnP: Remove iOS 7 compatibility code

Wrong:

Remove iOS 7 compatibility code => Lack of context

VLCNetworkServer: Remove iOS 7 compatibility code => Incomplete file name

VLCNetworkServerBrowserUPnP.m: Remove iOS 7 compatibility code => Useless file extension