Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 387d40f

Browse files
author
Kerr Marin Miller
committed
Fix a couple of typos, use guard instead of if let
1 parent 773a6b7 commit 387d40f

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

swift/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Component {
9393
}
9494
```
9595

96-
Use calculated properies instead of getter and setter functions:
96+
Use computed properties instead of getter and setter functions:
9797

9898
```swift
9999
class Component {
@@ -144,7 +144,7 @@ Try to wrap comments to 100 characters, though.
144144
For Dictionary and Array literals, use python-style indentation:
145145

146146
```swift
147-
let nameMap: [String: String] = [
147+
let nameMap = [
148148
"George": "Jetson",
149149
"Astro": "Boy",
150150
// etc.
@@ -217,7 +217,7 @@ Avoid this design pattern.
217217

218218
Use `let` unless the variable will be mutated.
219219

220-
delegates
220+
Delegates
221221
=========
222222

223223
Use the `weak` modifier for `delegate` properties.
@@ -354,12 +354,12 @@ Group helper functions into a `struct` rather than a `class`.
354354
Extensions
355355
==========
356356

357-
Create `extension`s to classes when you will use those functions in alot of places. Otherwise use [Helper functions](#Helper functions).
357+
Create `extension`s to classes when you will use those functions in a lot of places. Otherwise use [Helper functions](#Helper functions).
358358

359359
Layout
360360
======
361361

362-
Prefer Autolayout over springs+struts (autoresizing mask). Autolayout automatically handles many things that springs+struts doesn't (status bar hiding/showing, device rotation)
362+
Prefer Autolayout over springs+struts (autoresizing mask). Autolayout automatically handles many things that springs+struts doesn't (status bar hiding/showing, device rotation)
363363

364364
Other useful patterns
365365
=====================
@@ -369,25 +369,25 @@ Generic functions:
369369
https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Generics.html#//apple_ref/doc/uid/TP40014097-CH26-ID181
370370

371371
```swift
372-
func getValue<T>(dictionary: [String: AnyObject], key: String, errorHandler: String -> Void)) -> T? {
373-
if let value = dictionary[key] {
374-
if let value = value as? T {
375-
return value
376-
} else {
377-
errorHandler("\(key) is not a \(T.self)")
378-
}
379-
} else {
372+
func getValue<T>(dictionary: [String: AnyObject], key: String, errorHandler: String -> Void) -> T? {
373+
guard let value = dictionary[key] else {
380374
errorHandler("\(key) is not present")
375+
return nil
376+
}
377+
378+
guard let rightType = value as? T else {
379+
errorHandler("\(key) is not a \(T.self)")
380+
return nil
381381
}
382382

383-
return nil
383+
return rightType
384384
}
385385
```
386386

387-
Note that the type T is inferred by what you assign `getValue()` to. So in this case getValue() infers String? because `message` is a String?.
387+
Note that the type `T` is inferred by what you assign `getValue()` to. So in this case getValue() infers `String?` because `message` is a `String?`.
388388

389389
```swift
390390
let message: String? = getValue(dictionary, "message") { error in
391-
println(error)
391+
print(error)
392392
}
393393
```

0 commit comments

Comments
 (0)