Skip to content

Instantly share code, notes, and snippets.

View ManagementFunction.swift
// Management Function
func handleCarStarted()
{
turnLights(on: true)
turnAC(on: true
}
View RouterFunction.swift
// Router Function
private func turnLights(on shouldTurnLightsOn: Bool)
{
if shouldTurnLightsOn
{
turnExteriorLightsOn()
checkForBurnedBulbs()
}
else { turnExteriorLightsOff() }
// When an if statment has only 1 thing to execute i like to write it
View ExecutionFunctions.swift
// Execution Functions
private func turnExteriorLightsOn()
{
leftFrontLight .isOn = true
rightFrontLight.isOn = true
leftBackLight .isOn = true
rightBackLight .isOn = true
}
private func checkForBurnedBulbs()
{
View Car.swift
class Car: Vehicle {
// Informer Functions
override func engineStarted() {
super.engineStarted()
handleCarStarted()
}
// Management Functions
private func handleCarStarted() {
View CarExtension.swift
extension Car {
// Execution Functions
private func turnExteriorLightsOn() {
leftFrontLight .isOn = true
rightFrontLight.isOn = true
leftBackLight .isOn = true
rightBackLight .isOn = true
}
View isHidden.swift
public var isHidden: Bool {
return alpha == 0.0
}
if containerView.isHidden
View positionedVerticaly.swift
private var positionedVerticaly: Bool {
return view.frame.width/2 == centerX
}
if positionedVerticaly
if positionedVerticaly && positionedHorizontally
VS
if isPositionedVerticaly
if isPositionedVerticaly && isPositionedHorizontally
View isPositionedVerticaly.swift
public var isPositionedVerticaly: Bool {
return positionedVerticaly
}
if containerView.isPositionedVerticaly
View dataHasUpdated.swift
delegate.dataHasUpdated()
func dataHasUpdated() {
//Someone is informing you that something has happened
}
View dateFormatterExample.swift
if let date = dateFormatter.parseDate(from: string) {
postUploadDate = date
}