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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
Copyright (c) 2015-2016 Spotify AB.
This work is licensed under a Creative Commons Attribution 4.0 International License.
Example:
"bar")
Not:
"bar" )
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"};
ctionary *dict = @{
y1" : @"highway",
y2" : @"heart",
if
/ for
/ while
/ do
-while
statements. Even if its a one-liner:itsMagic) {
[self makeItEverlasting];
else
clauses after the previous closing bracket on the same line.hasClue) {
knowExactlyWhatToDo();
se if (seeItAllSoClear) {
writeItDown();
se {
sing();
dance();
//
style for single line comments or when appending comments in the same line of code./* */
style for multi-line 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.
Cmd
-/
to see this in action. Make sure to use the available markup tags like @param
,
@return
, etc. (these will be auto-generated for you by Xcode). The ///
form is preferred for single line
comments, and /** */
for multi-line comments. Use the same formatting as in the example block above.#pragma mark
to mark related groups of methods.#define
.rn NSString * const SPTCodeStandardErrorDomain;
Example:
oid)setFireToTheRain:(id)rain
if ([_rain isEqualTo:rain]) {
return;
}
_rain = rain;
Example:
nstancetype)init
self = [super init];
if (self) {
// initialize instance variables here
}
return self;
#import <Foundation/Foundation.h>
@import Foundation;
NS_ASSUME_NONNULL_BEGIN
and NS_ASSUME_NONNULL_END
in header files, and explicitly add nullable
when needed. Example:ort <Foundation/Foundation.h>
@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
customTitle:(nullable NSString *)customTitle;
@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.