Skip to content

Instantly share code, notes, and snippets.

View sjavora's full-sized avatar

Šimon Javora sjavora

  • Brno, Czech Republic
  • 16:24 (UTC +02:00)
View GitHub Profile
@sjavora
sjavora / Shuffled.swift
Created September 28, 2019 14:21
A property wrapper that returns elements in a random order.
@propertyWrapper
struct Shuffled<T: MutableCollection & RandomAccessCollection> {
var wrappedValue: T {
var value = baseValue
value.shuffle()
return value
}
private var baseValue: T
@sjavora
sjavora / Clamped.swift
Created September 28, 2019 13:50
A property wrapper that clamps its value to the specified range
@propertyWrapper
struct Clamped<T: Comparable> {
var wrappedValue: T {
didSet {
wrappedValue = Self.value(wrappedValue, clampedTo: range)
}
}
private let range: ClosedRange<T>
@sjavora
sjavora / Trimmed.swift
Last active September 28, 2019 13:38
A property wrapper that trims the selected characters from a String
import Foundation
@propertyWrapper
struct Trimmed {
var wrappedValue: String {
didSet {
wrappedValue = wrappedValue.trimmingCharacters(in: charactersToTrim)
}
}
@sjavora
sjavora / Truncated.swift
Created September 28, 2019 13:32
A property wrapper that truncates a string
@propertyWrapper
struct Truncated {
var wrappedValue: String {
didSet {
wrappedValue = String(wrappedValue.prefix(maxLength))
}
}
let maxLength: Int

Keybase proof

I hereby claim:

  • I am sjavora on github.
  • I am simon_javora (https://keybase.io/simon_javora) on keybase.
  • I have a public key ASCIAa-T6QKjm05-UteSIKJAnC2blKUSLOdU-Dvq4S5dxAo

To claim this, I am signing this object: