Skip to content

Instantly share code, notes, and snippets.

@twittemb
Created January 1, 2018 23:27
Show Gist options
  • Select an option

  • Save twittemb/8b59b2aee83221f488569fb968e1f957 to your computer and use it in GitHub Desktop.

Select an option

Save twittemb/8b59b2aee83221f488569fb968e1f957 to your computer and use it in GitHub Desktop.
private var subjectContext: UInt8 = 0
/// a Stepper has only one purpose: emit Steps that correspond to
/// specific navigation states.
/// The state changes lead to navigation actions in the context of
/// a specific Flow
public protocol Stepper: Synchronizable {
/// the Rx Obsersable that will trigger new Steps
var steps: Observable<Step> { get }
}
public extension Stepper {
/// The step in which to publish new Steps
public var step: BehaviorSubject<Step> {
return self.synchronized {
if let subject = objc_getAssociatedObject(self, &subjectContext)
as? BehaviorSubject<Step> {
return subject
}
let newSubject = BehaviorSubject<Step>(value: NoStep())
objc_setAssociatedObject(self,
&subjectContext,
newSubject,
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return newSubject
}
}
/// the Rx Obsersable that will trigger new Steps
public var steps: Observable<Step> {
return self.step.asObservable()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment