spotify/ios-style

Name: ios-style

Owner: Spotify

Description: Guidelines for iOS development in use at Spotify

Created: 2015-02-03 10:15:41.0

Updated: 2018-04-29 11:10:42.0

Pushed: 2017-04-16 19:44:49.0

Homepage: null

Size: 13

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Spotify Objective-C Coding Style

Version: 0.9.0

Our general coding conventions at Spotify are documented on an internal wiki, but specifics for Objective-C and Objective-C++ code in the iOS client are documented here.

License

Copyright (c) 2015-2016 Spotify AB.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Table of Contents
  1. Spacing, Lines and Formatting
  2. Brackets
  3. Naming
  4. Comments
  5. Pragma Marks
  6. Constants
  7. Return Early
  8. Initializers
  9. Headers
  10. Nullability
  11. Strings
  12. Dot Notation
  13. Categories
Spacing, Lines and Formatting
Line length
Whitespace

Example:

"bar") 

Not:

 "bar" )
Containers
ray *array = @[@"uno", @"dos", @"tres", @"cuatro"];
ray *array = @[
@"This is how we do, yeah, chilling, laid back",
@"Straight stuntin? yeah we do it like that",
@"This is how we do, do do do do, this is how we do",

ctionary *dict = @{@"key" : @"highway"};
Brackets
itsMagic) {
[self makeItEverlasting];

hasClue) {
knowExactlyWhatToDo();
se if (seeItAllSoClear) {
writeItDown();
se {
sing();
dance();

Naming
Comments

Example:


s is a multi-line comment. The opening and closing markers are on their
 lines.

s is a new paragraph in the same block comment.


(); // Hammer-time!

his is a very brief comment.
Pragma Marks
Constants
rn NSString * const SPTCodeStandardErrorDomain;
Return Early

Example:

oid)setFireToTheRain:(id)rain

if ([_rain isEqualTo:rain]) {
    return;
}

_rain = rain;

Initializers

Example:

nstancetype)init 

self = [super init];

if (self) {
    // initialize instance variables here
}

return self;

Headers
Nullability

@protocol SPTPlaylist;

NS_ASSUME_NONNULL_BEGIN

typedef void(^SPTSomeBlock)(NSData * Nullable data, NSError * Nullable error);

@interface SPTYourClass : NSObject

@property (nonatomic, copy, readonly, nullable) NSString *customTitle; @property (nonatomic, strong, readonly) id playlist;

@end

NS_ASSUME_NONNULL_END

ngs
---
l strings presented to the user should be localized.

Notation
--------
e bracket notation when calling non-accessor methods:

[self doSomething];

e bracket notation when accessing globals through a class method:

[MyClass sharedInstance];

t and access properties using dot notation:

self.myString = @“A string”;

cept in the `init` or `dealloc` methods, always use the ivar directly there:

_myString = nil;

gories
------
thods in categories on non-Spotify classes must be prefixed `spt_` to avoid name clashes.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.