Skip to content

Instantly share code, notes, and snippets.

View prachigauriar's full-sized avatar

Prachi Gauriar prachigauriar

  • New York
View GitHub Profile
@prachigauriar
prachigauriar / Slider+LogarithmicScale.swift
Last active April 9, 2025 06:19
SwiftUI Slider with Logarithmic Scale
extension Binding where Value == Double {
/// Returns a new version of the binding that scales the value logarithmically using the specified base. That is,
/// when getting the value, `log_b(value)` is returned; when setting it, the new value is `pow(base, newValue)`.
///
/// - Parameter base: The base to use.
func logarithmic(base: Double = 10) -> Binding<Double> {
Binding(
get: {
log10(self.wrappedValue) / log10(base)
},
@prachigauriar
prachigauriar / FormattedTextFieldView.swift
Last active January 19, 2023 20:58
Trying (and failing) to use formatters SwiftUI TextFields
import Foundation
import SwiftUI
struct FormattedTextFieldView : View {
@State private var double = 0.5
@State private var nsNumber: NSNumber = 0.5
static let numberFormatter: NumberFormatter = {
@prachigauriar
prachigauriar / ByteFormatStyle.swift
Last active December 5, 2024 19:25
ByteFormatStyle
import Foundation
struct ByteFormatStyle<Bytes> : FormatStyle, Hashable, Sendable where Bytes : Collection, Bytes.Element == UInt8 {
typealias FormatInput = Bytes
typealias FormatOutput = String
var radix: Int = 16
var uppercase: Bool = false