@@ -82,7 +82,7 @@ in the following code snippet, ``a.aProperty``, ``a.doSomething()`` and
82
82
dynamic doSomethingElse() { ... }
83
83
}
84
84
85
- class B : A {
85
+ class B: A {
86
86
override var aProperty {
87
87
get { ... }
88
88
set { ... }
@@ -155,7 +155,7 @@ assuming ``E``, ``F`` do not have any overriding declarations in the same file:
155
155
}
156
156
157
157
class F {
158
- fileprivate var myPrivateVar : Int
158
+ fileprivate var myPrivateVar: Int
159
159
}
160
160
161
161
func usingE(_ e: E) {
@@ -193,11 +193,11 @@ Array.
193
193
194
194
// Don't use a class here.
195
195
struct PhonebookEntry {
196
- var name : String
197
- var number : [Int]
196
+ var name: String
197
+ var number: [Int]
198
198
}
199
199
200
- var a : [PhonebookEntry]
200
+ var a: [PhonebookEntry]
201
201
202
202
Keep in mind that there is a trade-off between using large value types and using
203
203
reference types. In certain cases, the overhead of copying and moving around
@@ -277,9 +277,9 @@ safe.
277
277
278
278
::
279
279
280
- a : [Int]
281
- b : [Int]
282
- c : [Int]
280
+ a: [Int]
281
+ b: [Int]
282
+ c: [Int]
283
283
284
284
// Precondition: for all a[i], b[i]: a[i] + b[i] does not overflow!
285
285
for i in 0 ... n {
@@ -368,12 +368,12 @@ represented as values, so this example is somewhat realistic.
368
368
::
369
369
370
370
protocol P {}
371
- struct Node : P {
372
- var left, right : P?
371
+ struct Node: P {
372
+ var left, right: P?
373
373
}
374
374
375
375
struct Tree {
376
- var node : P?
376
+ var node: P?
377
377
init() { ... }
378
378
}
379
379
@@ -402,8 +402,8 @@ argument drops from being O(n), depending on the size of the tree to O(1).
402
402
403
403
::
404
404
405
- struct Tree : P {
406
- var node : [P?]
405
+ struct Tree: P {
406
+ var node: [P?]
407
407
init() {
408
408
node = [thing]
409
409
}
@@ -435,13 +435,13 @@ construct such a data structure:
435
435
::
436
436
437
437
final class Ref<T> {
438
- var val : T
439
- init(_ v : T) {val = v}
438
+ var val: T
439
+ init(_ v: T) {val = v}
440
440
}
441
441
442
442
struct Box<T> {
443
- var ref : Ref<T>
444
- init(_ x : T) { ref = Ref(x) }
443
+ var ref: Ref<T>
444
+ init(_ x: T) { ref = Ref(x) }
445
445
446
446
var value: T {
447
447
get { return ref.val }
@@ -506,7 +506,7 @@ alive.
506
506
withExtendedLifetime(Head) {
507
507
508
508
// Create an Unmanaged reference.
509
- var Ref : Unmanaged<Node> = Unmanaged.passUnretained(Head)
509
+ var Ref: Unmanaged<Node> = Unmanaged.passUnretained(Head)
510
510
511
511
// Use the unmanaged reference in a call/variable access. The use of
512
512
// _withUnsafeGuaranteedRef allows the compiler to remove the ultimate
@@ -540,7 +540,7 @@ protocols as class-only protocols to get better runtime performance.
540
540
541
541
::
542
542
543
- protocol Pingable : AnyObject { func ping() -> Int }
543
+ protocol Pingable: AnyObject { func ping() -> Int }
544
544
545
545
.. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
546
546
0 commit comments