Enum case names should be lowerCamelCase Open
MacOSX = "macosx"
- Read upRead up
- Exclude checks
lower-camel-case
method
and var
names should follow lowerCamelCase naming convention: first letter of the entire word is lowercase, but subsequent first letters are uppercase.
Method and selector names
Preferred
func someMethod() {
// method definition goes here
}
Not Preferred
func some-method() {
// method definition goes here
}
Variable names
Preferred
var someVariable = someValue
Not Preferred
var Some_Var1able = someValue
Colon at column 78 should have exactly one space after it Open
try moduleMapFile.write(toFile: moduleMapPath, atomically: true, encoding:String.Encoding.utf8)
- Read upRead up
- Exclude checks
colon-whitespace
There should be no whitespace preceding the colon, exactly one whitespace after the colon for:
* var
, class
, struct
, protocol
, extension
, func
, and tuple
declarations
* dict
literals and types
* case
statements
However, for conditional expressions there should be a single whitespace before and after the colon.
Variable declarations
Preferred
var x: Int = 2
Not Preferred
var x : Int
var y: String
Dictionary literals and types
Preferred
var x = [ 'key1': 1, 'key2': 2 ]
var y: [ Int: String ]
Not Preferred
var x = [ 'key1' : 1, 'key2': 3]
var y: [ Int : String ]
Case statements
Preferred
switch character {
case "a": doSomething(a);
default: alert();
}
Not Preferred
switch character {
case "a" : doSomething(a);
default: alert();
}
Class, Struct, Protocol, and Extension declarations
Preferred
class ClassName: BaseClass {
}
struct StructName: BaseStruct {
}
protocol ProtocolName: AnotherProtocol {
}
extension TypeName: ProtocolName {
}
Not Preferred
class ClassName : BaseClass {
}
struct StructName: BaseStruct {
}
protocol ProtocolName:AnotherProtocol {
}
extension TypeName : ProtocolName {
}
Tuple declarations
Preferred
var y = (key: 1, value: 2)
Not Preferred
var y = (key:1, value : 2)
Function declarations
Preferred
func someFunction<t: someclass u: someprotocol>(someT: T, someU: U) {
}</t:>
Not Preferred
func someFunction<t : someclass u:someprotocol>(someT: T, someU: U) {
}</t>
Conditional expressions
Preferred
var x = condition ? a : b
Not Preferred
var x = condition ? a: b
var x = condition ? a : b
Colon at column 23 should have exactly one space after it Open
return String(data:outputData, encoding: String.Encoding.utf8)
- Read upRead up
- Exclude checks
colon-whitespace
There should be no whitespace preceding the colon, exactly one whitespace after the colon for:
* var
, class
, struct
, protocol
, extension
, func
, and tuple
declarations
* dict
literals and types
* case
statements
However, for conditional expressions there should be a single whitespace before and after the colon.
Variable declarations
Preferred
var x: Int = 2
Not Preferred
var x : Int
var y: String
Dictionary literals and types
Preferred
var x = [ 'key1': 1, 'key2': 2 ]
var y: [ Int: String ]
Not Preferred
var x = [ 'key1' : 1, 'key2': 3]
var y: [ Int : String ]
Case statements
Preferred
switch character {
case "a": doSomething(a);
default: alert();
}
Not Preferred
switch character {
case "a" : doSomething(a);
default: alert();
}
Class, Struct, Protocol, and Extension declarations
Preferred
class ClassName: BaseClass {
}
struct StructName: BaseStruct {
}
protocol ProtocolName: AnotherProtocol {
}
extension TypeName: ProtocolName {
}
Not Preferred
class ClassName : BaseClass {
}
struct StructName: BaseStruct {
}
protocol ProtocolName:AnotherProtocol {
}
extension TypeName : ProtocolName {
}
Tuple declarations
Preferred
var y = (key: 1, value: 2)
Not Preferred
var y = (key:1, value : 2)
Function declarations
Preferred
func someFunction<t: someclass u: someprotocol>(someT: T, someU: U) {
}</t:>
Not Preferred
func someFunction<t : someclass u:someprotocol>(someT: T, someU: U) {
}</t>
Conditional expressions
Preferred
var x = condition ? a : b
Not Preferred
var x = condition ? a: b
var x = condition ? a : b