Skip to content

Instantly share code, notes, and snippets.

@appleios
Last active September 29, 2015 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appleios/56c6d88b3905bc715e2b to your computer and use it in GitHub Desktop.
Save appleios/56c6d88b3905bc715e2b to your computer and use it in GitHub Desktop.
my objc codestyle

Original

See original in Ray Wenderlich code style guide

Diff

Functions are not ifs

Put bracket on next line for functions.

Preferred:

- (void)someMethod 
{
  if ([smth boolValue]) {
    // then something
  }
}

Not Preferred:

- (void)someMethod {
  if ([smth boolValue]) {
    //Do something important
  }
}

NSInteger not int

Use NSInteger, instead of int; NSUInteger vs unsigned int; etc

Preferred:

- (void)someMethodWithInteger:(NSInteger)myInt
{
}

Not Preferred:

- (void)someMethodWithInteger:(int)myInt
{
}

No empty lines and spaces needed

Don't use more than one empty line, no spaces in method name. It pollutes code and makes it hard to read.

Preferred:

- (void)someMethodWithInt:(NSInteger)myValue
{
  if(someCondition) {
    [someObject someMethod];
  }
}

Not Preferred:

///////////////
/////// my super duper function /////
//////////////


- (void)  someMethodWithInt  :  (NSInteger)  myValue
{


  if    (someCondition){
    [ someObject   someMethod  ];
    
    
  }




}

Document your code

If your code intended to be shared with other - is a public API => write docs when possible.

Preferred:

/**
 A class method for creating new entities.
 
 @returns Returns en entity with given integer number.
 
 @code
 id entry = [MyClass createNewEntryWithInteger:147];
 @endcode
 
 Example above returns object of class MyClass.
 */
+ (void)createNewEntryWithInteger:(NSInteger)entryInteger
{
}

Not Preferred:

+ (void)createNewEntryWithInteger:(NSInteger)entryInteger
{
}

Use pragma mark correctly

There are several ways to use pragma mark correctly, please use them.

Preferred:

#pragma mark - this puts hline before and after -
#pragma mark - this puts hline before
#pragma mark this puts hline after -
#pragma mark just bold text

Not Preferred:

#pragma mark -=dont do this please=-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment