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
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) | |
} |
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
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) | |
} | |
} |
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 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 { |
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
guard thisStatmentIsTrue else { assertionFailure("❌ Assert at: \(#line)") ; 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
class Car: Vehical { | |
// *Old* code Represented as the "False" state of the toggle | |
func drive(to geoLocation: Position) { | |
} | |
// *New* code Represented as the "True" state of the toggle | |
func fly(to geoLocation: Position) { | |
} |
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 CarFleet { | |
func moveCarsToPosition(cars: [Car], position: Position) { | |
cars.forEach({ | |
if Toggles.Vehical.carsCanFly.enabled { | |
fly(to: location) | |
} else { | |
drive(to: location) | |
} | |
}) | |
} |
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
// MARK: - Toggle Logic For CarFleet | |
protocol CarFleetFeatureToggleLogic { | |
var fuelToUse: Fuel { get } | |
func transport(car: Car, to position: Position) | |
} | |
extension CarFleetFeatureToggleLogic where Self: CarFleet { | |
/** | |
Get the fuel to be used on cars. |
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 CarFleet: CarFleetFeatureToggleLogic { | |
func moveCarsToPosition(cars: [Car], position: Position) { | |
cars.forEach({ transport(car: $0, to: position) }) | |
} | |
func refuel(cars: [Car]) { | |
cars.forEach({ refuel(car: $0, using: fuelToUse) }) | |
} | |
func refuel(car: Car, using: Fuel) { |
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 CellType { | |
var generator: TableViewCellGeneratorProtocol.Type { get } | |
var associatedObject: Any? { get } | |
var cellHeight: CGFloat { get } | |
} |
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
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return tableStructure.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cellType = tableStructure[indexPath.row] | |
let cell = cellType.generator.cell(for: indexPath, inTableView: tableView) | |
cellType.generator.configure(cell: cell, using: cellType.associatedObject, at: indexPath) | |
return cell | |
} |