Skip to content

Instantly share code, notes, and snippets.

@jkubicek
Created June 15, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkubicek/4c217e1c299b82efe96e75d12821ae28 to your computer and use it in GitHub Desktop.
Save jkubicek/4c217e1c299b82efe96e75d12821ae28 to your computer and use it in GitHub Desktop.
Swift Formatting
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