Skip to content

Instantly share code, notes, and snippets.

View Maschina's full-sized avatar

Robert Hahn Maschina

  • 16:35 (UTC +02:00)
View GitHub Profile
@Maschina
Maschina / MeasurementField.swift
Created May 30, 2022 18:55
A customized text field that allows numbers only and validates the user input
import SwiftUI
/// A customized text field that allows numbers only and validates the user input
struct MeasurementField: NSViewRepresentable {
typealias NSViewType = NSTextField
@Binding var measurement: Measurement<Unit>
let range: ClosedRange<Double>
let measurementFormatter: MeasurementFormatter
let numberFormatter: NumberFormatter
@Maschina
Maschina / compileTime.swift
Created June 13, 2021 10:34
Get compilation time in Swift. Credits go to Alain. T (https://stackoverflow.com/a/38421481/873072)
/// Get the build date and time
var compileTime: Date {
let bundleName = Bundle.main.infoDictionary!["CFBundleName"] as? String ?? "Info.plist"
if let infoPath = Bundle.main.path(forResource: bundleName, ofType: nil),
let infoAttr = try? FileManager.default.attributesOfItem(atPath: infoPath),
let infoDate = infoAttr[FileAttributeKey.creationDate] as? Date
{ return infoDate }
return Date()
}