Created
June 15, 2016 19:01
-
-
Save jkubicek/4c217e1c299b82efe96e75d12821ae28 to your computer and use it in GitHub Desktop.
Swift Formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
//: # Collections | |
// This is bad | |
let badArray = ["one", "two", "apple", | |
"orange", "elephant", "orangutan"] | |
// This is good | |
let goodArray = ["one", | |
"two", | |
"apple", | |
"orange", | |
"elephant", | |
"orangutan"] | |
//: # Chained Methods | |
// This is bad | |
let badBigWordCharCount = goodArray.flatMap { | |
$0.characters.count }.filter { $0 > 10 }.reduce(0) { $0 + $1 } | |
// This is good | |
let goodBigWordCharCount = goodArray | |
.map { $0.characters.count } | |
.filter { $0 > 10 } | |
.reduce(0) { $0 + $1 } | |
//: # Long method signatures | |
// This is bad | |
UIView.animateWithDuration(0.25, delay: 1, usingSpringWithDamping: 0.5, | |
initialSpringVelocity: 26, options: [], | |
animations: {}, completion: { _ in }) | |
// This is good | |
UIView.animateWithDuration(0.25, | |
delay: 1, | |
usingSpringWithDamping: 0.5, | |
initialSpringVelocity: 26, | |
options: [], | |
animations: {}, | |
completion: { _ in }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment