- Don't add code cruft. Avoid parentheses around conditions in if-statements or with the
return
keyword. Don't add semicolons except where syntactically demanded in statements or to separate statements on the same line. - Don't use ALL_CAPS; use camelCase
- Don't fight type inference. Use enumeration prefixes, self-references, and class names (with constructors) only when necessary or to clarify coding intent.
- Don't use
var
whenlet
is appropriate, especially for properties. The compiler better optimizeslet
statements for items whose values will not change during their lifetime. For example, Apple writes, "It is good practice to create immutable collections in all cases where the collection does not need to change. Doing so enables the Swift compiler to optimize the performance of the collections you create." - Don't use classes when structs will do. Use class
This file contains 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
# Run Script Build Phase | |
BuildPlist=${INFOPLIST_FILE} | |
CFBundleVersion=$(git rev-parse --short HEAD) | |
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "${BuildPlist}" |
This file contains 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
// | |
// FlagView.swift | |
// Bandeira Brasil | |
// | |
// Created by Danilo Altheman on 01/07/14. | |
// Copyright (c) 2014 Quaddro. All rights reserved. | |
// | |
import UIKit |
This file contains 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
extension UIColor { | |
convenience init(hex: UInt32) { | |
var r: CGFloat = (CGFloat((hex & 0xFF0000) >> 16) / 255.0) | |
var g: CGFloat = (CGFloat((hex & 0x00FF00) >> 8) / 255.0) | |
var b: CGFloat = (CGFloat (hex & 0x0000FF) / 255.0) | |
self.init(red: r, green: g, blue: b, alpha: 1.0) | |
} | |
} | |
let green = UIColor(hex: 0x00A859) |
This file contains 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
//------------------------------------------------------------------------------ | |
// Aula 4 - 27-11-2014 - Funcional - Map, Filter, Reduce | |
//------------------------------------------------------------------------------ | |
//-- Com cenas dos proximos capitulos (Generics, Structs) | |
var numeros = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] | |
//-- Sintaxe diferente | |
reduce(numeros, 0, +) | |
reduce(numeros, 1, *) |
This file contains 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
Show hidden characters
{ | |
"auto_complete_commit_on_tab": true, | |
"auto_complete_with_fields": true, | |
"bold_folder_labels": true, | |
"caret_style": "solid", | |
"close_windows_when_empty": true, | |
"color_scheme": "Packages/Tomorrow Color Schemes/Tomorrow-Night.tmTheme", | |
"create_window_at_startup": false, | |
"drag_text": false, | |
"ensure_newline_at_eof_on_save": true, |
This file contains 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 Foundation | |
extension Dictionary { | |
func fetch(_ key: Key, defaultValue: @autoclosure () -> Value) -> Value { | |
return self[key] ?? defaultValue() | |
} | |
func fetch<T>(_ key: Key, castTo type: T.Type, defaultValue: @autoclosure () -> T) -> T { | |
return self[key] as? T ?? defaultValue() | |
} |
This file contains 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
{ | |
"continents": { | |
"AF": "África", | |
"AN": "Antártica", | |
"AS": "Asia", | |
"EU": "Europa", | |
"NA": "América do Norte", | |
"OC": "Oceania", | |
"SA": "América do Sul" | |
}, |
This file contains 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
extension Array { | |
func shuffle() -> [Element] { | |
var shuffledCollection = self | |
var remainingElements = self.count | |
while remainingElements > 0 { | |
let currentIndex = remainingElements - 1 | |
let newIndex = Int(arc4random_uniform(UInt32(remainingElements))) | |
let temp = shuffledCollection[currentIndex] |
This file contains 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
extension Character { | |
var uppercaseCharacter: Character { | |
return Character(String(self).uppercaseString) | |
} | |
var lowercaseCharacter: Character { | |
return Character(String(self).lowercaseString) | |
} | |
func isUppercaseCharacter() -> Bool { |