Contents

print(_:to:)

Prints log messages for all publishing events.

Declaration

func print(_ prefix: String = "", to stream: (any TextOutputStream)? = nil) -> Publishers.Print<Self>

Parameters

  • prefix:

    A string —- which defaults to empty -— with which to prefix all log messages.

  • stream:

    A stream for text output that receives messages, and which directs output to the console by default. A custom stream can be used to log messages to other destinations.

Return Value

A publisher that prints log messages for all publishing events.

Discussion

Use print(_:to:) to log messages the console.

In the example below, log messages are printed on the console:

let integers = (1...2)
cancellable = integers.publisher
   .print("Logged a message", to: nil)
   .sink { _ in }

// Prints:
//  Logged a message: receive subscription: (1..<2)
//  Logged a message: request unlimited
//  Logged a message: receive value: (1)
//  Logged a message: receive finished

See Also

Debugging