Skip to content

Instantly share code, notes, and snippets.

View DateFormatter.swift
extension DateFormatter
{
private enum DateFormats: String, CaseIterable {
case basicDate = "yyyy-MM-dd"
case basicDateWithTime_Without_Miliseconds = "yyyy-MM-dd HH:mm:ss"
case basicDateWithTime_With_Miliseconds = "yyyy-MM-dd HH:mm:ss.SSSSS"
case basicDateWithTime_WithX_Miliseconds = "yyyy-MM-dd HH:mm:ss.SSSSx"
var withTimeStamp: String {
switch self {
View parseDate.swift
func parseDate(from string: String?) -> Date {
guard let dateString = string else { return Date() }
if let date = self.date(from: dateString) {
return date
}
else {
return locateCorrectFormat(for: dateString)
}
}
View locateCorrectFormat.swift
private func locateCorrectFormat(for dateString: String) -> Date {
for dateFormat in DateFormats.allCases {
if let date = parse(dateString, using: dateFormat) {
return date
}
}
return useRegexToExtractDate(from: dateString)
}
View dateFormatterExample.swift
if let date = dateFormatter.parseDate(from: string) {
postUploadDate = date
}
View dataHasUpdated.swift
delegate.dataHasUpdated()
func dataHasUpdated() {
//Someone is informing you that something has happened
}
View isPositionedVerticaly.swift
public var isPositionedVerticaly: Bool {
return positionedVerticaly
}
if containerView.isPositionedVerticaly
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 isHidden.swift
public var isHidden: Bool {
return alpha == 0.0
}
if containerView.isHidden
View CarExtension.swift
extension Car {
// Execution Functions
private func turnExteriorLightsOn() {
leftFrontLight .isOn = true
rightFrontLight.isOn = true
leftBackLight .isOn = true
rightBackLight .isOn = true
}
View Car.swift
class Car: Vehicle {
// Informer Functions
override func engineStarted() {
super.engineStarted()
handleCarStarted()
}
// Management Functions
private func handleCarStarted() {