Skip to content

Debouncing TextField bindings makes last input char lost #981

Answered by tgrapperon
oskargargas asked this question in Q&A
Discussion options

You must be logged in to vote

In case having a reference type in State is unavoidable, this property wrapper may help standardizing things:

@propertyWrapper
public struct ReferenceState<State>: Equatable where State: AnyObject {
  struct Token: Hashable {
    let sec: Int
    let nsec: Int
    init() {
      var uptime = timespec()
      guard clock_gettime(CLOCK_MONOTONIC_RAW, &uptime) == 0 else {
        fatalError("Unable to retrieve uptime")
      }
      self.sec = uptime.tv_sec
      self.nsec = uptime.tv_nsec
    }
  }

  private var didChangeToken: Token
  public var wrappedValue: State

  public init(wrappedValue: State) {
    self.wrappedValue = wrappedValue
    self.didChangeToken = Token()
  }

  public var 

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@tgrapperon
Comment options

@tgrapperon
Comment options

@tgrapperon
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by oskargargas
Comment options

You must be logged in to vote
1 reply
@tgrapperon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants