Browse Questions
  • TSCellSeal(key:) uses the bytes you supply directly as the symmetric key, while TSCellSeal(passphrase:) runs a human-typed string through a deliberately slow key derivation function first.
  • A property wrapper adds custom logic around getting and setting a property.
  • withCheckedContinuation bridges old callback-based APIs into the async/await world.
  • A stored property keeps a value in the instance's memory, while a computed property stores nothing and calculates its value every time it is read.

Answer: A property wrapper adds custom logic around getting and setting a property. SwiftUI's @State, @Binding, and @Published are all property wrappers.

Code Example:

@propertyWrapper
struct Clamped {
    private var value: Int
    let range: ClosedRange<Int>

    var wrappedValue: Int {
        get { value }
        set { value = min(max(newValue, range.lowerBound), range.upperBound) }
    }

    init(wrappedValue: Int, _ range: ClosedRange<Int>) {
        self.range = range
        self.value = min(max(wrappedValue, range.lowerBound), range.upperBound)
    }
}

struct Player {
    @Clamped(0...100) var health: Int = 100
}

var player = Player()
player.health = 150  // clamped to 100
player.health = -10  // clamped to 0