Skip to content

Commit c16cb8d

Browse files
committed
A little section rearranging
close kodecocodes#46
1 parent 4853da4 commit c16cb8d

File tree

1 file changed

+67
-64
lines changed

1 file changed

+67
-64
lines changed

README.markdown

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
88

99
## Table of Contents
1010

11-
* [Language](#language)
12-
* [Spacing](#spacing)
13-
* [Comments](#comments)
1411
* [Naming](#naming)
1512
* [Class Prefixes](#class-prefixes)
16-
* [Semicolons](#semicolons)
13+
* [Spacing](#spacing)
14+
* [Comments](#comments)
1715
* [Classes and Structures](#classes-and-structures)
16+
* [Use of Self](#use-of-self)
1817
* [Function Declarations](#function-declarations)
1918
* [Closures](#closures)
2019
* [Types](#types)
@@ -23,59 +22,12 @@ Writing Objective-C? Check out our [Objective-C Style Guide](https://github.com/
2322
* [Type Inference](#type-inference)
2423
* [Syntactic Sugar](#syntactic-sugar)
2524
* [Control Flow](#control-flow)
26-
* [Use of Self](#use-of-self)
25+
* [Semicolons](#semicolons)
26+
* [Language](#language)
2727
* [Smiley Face](#smiley-face)
2828
* [Credits](#credits)
2929

3030

31-
## Language
32-
33-
Use US English spelling to match Apple's API.
34-
35-
**Preferred:**
36-
```swift
37-
var color = "red"
38-
```
39-
40-
**Not Preferred:**
41-
```swift
42-
var colour = "red"
43-
```
44-
45-
## Spacing
46-
47-
* Indent using 2 spaces rather than tabs to conserve space and help prevent line wrapping. Be sure to set this preference in Xcode.
48-
* Method braces and other braces (`if`/`else`/`switch`/`while` etc.) always open on the same line as the statement but close on a new line.
49-
50-
**Preferred:**
51-
```swift
52-
if user.isHappy {
53-
//Do something
54-
} else {
55-
//Do something else
56-
}
57-
```
58-
59-
**Not Preferred:**
60-
```swift
61-
if user.isHappy
62-
{
63-
//Do something
64-
}
65-
else {
66-
//Do something else
67-
}
68-
```
69-
70-
* There should be exactly one blank line between methods to aid in visual clarity and organization. Whitespace within methods should separate functionality, but having too many sections in a method often means you should refactor into several methods.
71-
72-
## Comments
73-
74-
When they are needed, use comments to explain **why** a particular piece of code does something. Comments must be kept up-to-date or deleted.
75-
76-
Avoid block comments inline with code, as the code should be as self-documenting as possible. *Exception: This does not apply to those comments used to generate documentation.*
77-
78-
7931
## Naming
8032

8133
Use descriptive names with camel case for classes, methods, variables, etc. Class names and constants in module scope should be capitalized, while method names and variables should start with a lower case letter.
@@ -125,11 +77,14 @@ class Guideline {
12577

12678
When referring to functions in prose (tutorials, books, comments) include the required parameter names from the caller's perspective.
12779

128-
12980
> The `dateFromString()` function is great.
81+
>
13082
> Call `convertPointAt(column:, row:)` from your `init()` method.
83+
>
13184
> The return value of `timedAction(delay:, perform:)` may be nil.
85+
>
13286
> Guideline objects only have two methods: `combineWithString(options:)` and `upvoteBy()`
87+
>
13388
> You shouldn't call the data source method `tableView(cellForRowAtIndexPath:)` directly.
13489
13590

@@ -154,25 +109,39 @@ If you need to expose a Swift type for use within Objective-C you can provide a
154109
```
155110

156111

157-
## Semicolons
158-
159-
Swift does not require a semicolon after each statement in your code. They are only required if you wish to combine multiple statements on a single line.
160-
161-
Do not write multiple statements on a single line separated with semicolons.
112+
## Spacing
162113

163-
The only exception to this rule is the `for-conditional-increment` construct, which requires semicolons. However, alternative `for-in` constructs should be used where possible.
114+
* Indent using 2 spaces rather than tabs to conserve space and help prevent line wrapping. Be sure to set this preference in Xcode.
115+
* Method braces and other braces (`if`/`else`/`switch`/`while` etc.) always open on the same line as the statement but close on a new line.
164116

165117
**Preferred:**
166118
```swift
167-
var swift = "not a scripting language"
119+
if user.isHappy {
120+
//Do something
121+
} else {
122+
//Do something else
123+
}
168124
```
169125

170126
**Not Preferred:**
171127
```swift
172-
var swift = "not a scripting language";
128+
if user.isHappy
129+
{
130+
//Do something
131+
}
132+
else {
133+
//Do something else
134+
}
173135
```
174136

175-
**NOTE**: Swift is very different to JavaScript, where omitting semicolons is [generally considered unsafe](http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript)
137+
* There should be exactly one blank line between methods to aid in visual clarity and organization. Whitespace within methods should separate functionality, but having too many sections in a method often means you should refactor into several methods.
138+
139+
## Comments
140+
141+
When they are needed, use comments to explain **why** a particular piece of code does something. Comments must be kept up-to-date or deleted.
142+
143+
Avoid block comments inline with code, as the code should be as self-documenting as possible. *Exception: This does not apply to those comments used to generate documentation.*
144+
176145

177146
## Classes and Structures
178147

@@ -217,7 +186,7 @@ The example above demonstrates the following style guidelines:
217186
+ Indent getter and setter definitions and property observers.
218187
+ Define multiple variables and structures on a single line if they share a common purpose / context.
219188

220-
## Use of Self
189+
### Use of Self
221190

222191
Avoid using `self` since Swift does not require it to access an object's properties or invoke its methods.
223192

@@ -386,6 +355,40 @@ for var i = 0; i < attendeeList.count; i++ {
386355
```
387356

388357

358+
## Semicolons
359+
360+
Swift does not require a semicolon after each statement in your code. They are only required if you wish to combine multiple statements on a single line.
361+
362+
Do not write multiple statements on a single line separated with semicolons.
363+
364+
The only exception to this rule is the `for-conditional-increment` construct, which requires semicolons. However, alternative `for-in` constructs should be used where possible.
365+
366+
**Preferred:**
367+
```swift
368+
var swift = "not a scripting language"
369+
```
370+
371+
**Not Preferred:**
372+
```swift
373+
var swift = "not a scripting language";
374+
```
375+
376+
**NOTE**: Swift is very different to JavaScript, where omitting semicolons is [generally considered unsafe](http://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript)
377+
378+
## Language
379+
380+
Use US English spelling to match Apple's API.
381+
382+
**Preferred:**
383+
```swift
384+
var color = "red"
385+
```
386+
387+
**Not Preferred:**
388+
```swift
389+
var colour = "red"
390+
```
391+
389392
## Smiley Face
390393

391394
Smiley faces are a very prominent style feature of the raywenderlich.com site! It is very important to have the correct smile signifying the immense amount of happiness and excitement for the coding topic. The closing square bracket `]` is used because it represents the largest smile able to be captured using ASCII art. A closing parenthesis `)` creates a half-hearted smile, and thus is not preferred.

0 commit comments

Comments
 (0)