Skip to content

on(_:)

MethodTryYourSize (Swift)

Window events: ready, open, close, size, loadError.

@discardableResult
public func on(_ handler: @escaping (Event) -> Void) -> TYSSubscription
handler@escaping (Event) -> VoidRequired

Called with each window event.

.ready(product: String)Optional

The window is shown and connected.

.open(product: String)Optional
.close(product: String)Optional
.size(SizeSelection)Optional

The shopper chose a size: preselect it.

.loadError(TryYourSizeError)Optional

Our window could not be reached, or this app is not registered for the key.

A subscription; cancel() stops the events.

let sub = tys.on { event in
switch event {
case .size(let selection): selectedSize = selection.size // "Use this size"
case .loadError(let error): print(error.code)
default: break
}
}

Was this page helpful?