Skip to content

Instantly share code, notes, and snippets.

// Management Function
func handleCarStarted()
{
turnLights(on: true)
turnAC(on: true
}
// 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
// Execution Functions
private func turnExteriorLightsOn()
{
leftFrontLight .isOn = true
rightFrontLight.isOn = true
leftBackLight .isOn = true
rightBackLight .isOn = true
}
private func checkForBurnedBulbs()
{
class Car: Vehicle {
// Informer Functions
override func engineStarted() {
super.engineStarted()
handleCarStarted()
}
// Management Functions
private func handleCarStarted() {
extension Car {
// Execution Functions
private func turnExteriorLightsOn() {
leftFrontLight .isOn = true
rightFrontLight.isOn = true
leftBackLight .isOn = true
rightBackLight .isOn = true
}
public var isHidden: Bool {
return alpha == 0.0
}
if containerView.isHidden
private var positionedVerticaly: Bool {
return view.frame.width/2 == centerX
}
if positionedVerticaly
if positionedVerticaly && positionedHorizontally
VS
if isPositionedVerticaly
if isPositionedVerticaly && isPositionedHorizontally
public var isPositionedVerticaly: Bool {
return positionedVerticaly
}
if containerView.isPositionedVerticaly
delegate.dataHasUpdated()
func dataHasUpdated() {
//Someone is informing you that something has happened
}
if let date = dateFormatter.parseDate(from: string) {
postUploadDate = date
}