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
// Like an if statement, guard executes statements based on a Boolean value of an expression. | |
// Unlike an if statement, guard statements only run if the conditions are not met. | |
// You can think of guard more like an Assert, but rather than crashing, you can gracefully exit. | |
func fooGuardNonOptional(x: Int) { | |
guard x > 0 else { | |
// Value requirements not met, do something | |
return | |
} | |
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
sectionLoop: for section in sections { | |
rowLoop: for row in rows { | |
if row.isMagical { | |
break sectionLoop | |
} | |
} | |
} |
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 | |
import RealmSwift | |
protocol CascadingDeletable { | |
var cascadingDeletions: [AnyObject?] { get } | |
} | |
extension Realm { | |
func delete<T: AnyObject>(_ objects: List<T>, cascade: Bool = true) where T: CascadingDeletable { |
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
enum Storyboard: String { | |
case menu = "Menu" | |
case login = "Login" | |
case profile = "Profile" | |
case map = "Map" | |
case settings = "Settings" | |
public func instantiate<VC: UIViewController>(_ viewController: VC.Type) -> VC { | |
guard let vc = UIStoryboard(name: self.rawValue, bundle: nil).instantiateViewController(withIdentifier: VC.storyboardIdentifier) as? VC | |
else { fatalError("Couldn't instantiate \(VC.storyboardIdentifier) from \(self.rawValue)") } |
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
protocol ReuseIdentifying { | |
static var reuseIdentifier: String { get } | |
} | |
extension ReuseIdentifying { | |
static var reuseIdentifier: String { | |
return String(describing: Self.self) | |
} | |
} |
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
/// Add a child view controller | |
/// | |
/// - Parameter child: The child view controller | |
func add(_ child: UIViewController) { | |
addChildViewController(child) | |
view.addSubview(child.view) | |
child.didMove(toParentViewController: self) | |
} | |
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 UIKit | |
extension URL { | |
func getValueForQueryParameter(name: String) -> String? { | |
let urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: true) | |
return urlComponents?.queryItems?.first(where: { (item) -> Bool in | |
item.name == name | |
})?.value | |
} |
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
disabled_rules: # rule identifiers to exclude from running | |
- force_cast | |
- legacy_constant | |
- legacy_constructor | |
- nesting | |
- trailing_whitespace | |
- type_name | |
- identifier_name | |
- cyclomatic_complexity | |
- explicit_self |
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
var test = [1, 2, 3] | |
var n = 5 | |
let limit = n > test.count ? test.count : n | |
var test2 = test[0..<limit] | |
var test3 = test.prefix(n) |
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
class RoutesViewController { | |
/// ... | |
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) { | |
if let index = self.shouldSelectPath(mapView, coordinate: coordinate, routes: results, currentRouteIndex: routeIndex) { | |
routeIndex = index | |
updateRoute() | |
} | |
} |
OlderNewer