View ContentViewModel.swift
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 NearbyInteraction | |
import MultipeerConnectivity | |
import Combine | |
var numberFormatter: NumberFormatter { | |
let numberFormatter = NumberFormatter() | |
numberFormatter.roundingMode = .halfEven | |
numberFormatter.maximumFractionDigits = 3 | |
numberFormatter.minimumFractionDigits = 3 |
View RandomDate.swift
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 | |
func generateRandomDate(daysBack: Int)-> Date?{ | |
let day = arc4random_uniform(UInt32(daysBack))+1 | |
let hour = arc4random_uniform(23) | |
let minute = arc4random_uniform(59) | |
let today = Date(timeIntervalSinceNow: 0) | |
let gregorian = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian) | |
var offsetComponents = DateComponents() |
View UIView+Nib.swift
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 UIView { | |
/// Load a view from a nib file and return it. | |
/// The Class and the Nib file must have the same name. | |
/// The nib file should contain only one view. | |
/// | |
/// - Returns: The first view found in the nib file. | |
static func loadInstanceFromNib<T: UIView>() -> T? { | |
return Bundle.main.loadNibNamed(String(describing: classForCoder()), owner: self, options: nil)?[0] as? T | |
} | |
} |
View UIColor+Hex.swift
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 UIColor { | |
/// Init a UIColor base on the color hexadecimal value | |
/// | |
/// - Parameters: | |
/// - hex: Hexadecimal code of the color | |
/// - alpha: Alpha opacity, between 0 and 1 | |
public convenience init(hex: UInt, alpha: CGFloat) { | |
self.init( | |
red: CGFloat((hex & 0xFF0000) >> 16) / 255.0, | |
green: CGFloat((hex & 0x00FF00) >> 8) / 255.0, |
View Log.swift
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 | |
public struct Log { | |
fileprivate enum Tag: String { | |
case verbose = "🔷" | |
case success = "✅" | |
case warning = "⚠️" | |
case error = "🚫" | |
case json = "📦" | |
} |
View Permutation.swift
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 Permutator { | |
class func permutation(_ str: String) -> Set<String> { | |
return permutation(str, prefix: "") | |
} | |
private class func permutation(_ str: String, prefix: String) -> Set<String> { | |
if str.characters.count == 0 { | |
return [prefix] | |
} | |
View Quicksort.swift
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 quicksort<T: Comparable>(_ arr: [T]) -> [T] { | |
guard arr.count > 1 else { | |
return arr | |
} | |
let pivot = arr[arr.count / 2] | |
var left = [T]() | |
var equal = [T]() | |
var right = [T]() | |