Instance Method


Republishes elements while a error-throwing predicate closure indicates publishing should continue.


func tryPrefix(while predicate: @escaping (Upstream.Output) throws -> Bool) -> Publishers.TryPrefixWhile<Publishers.Share<Upstream>>



A closure that takes an element as its parameter and returns a Boolean value indicating whether publishing should continue.

Return Value

A publisher that passes through elements until the predicate throws or indicates publishing should finish.


The publisher finishes when the closure returns false. If the closure throws, the publisher fails with the thrown error.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software