Guides and Sample Code


Playground Book Format Reference

On This Page

PlaygroundRemoteLiveViewProxyDelegate Protocol

A type that supports receiving asynchronous messages from an always-on live view.


This protocol enables an object to become the delegate of a PlaygroundRemoteLiveViewProxy Class object. Use this protocol to receive messages from a remote proxy and to be informed when the connection with the remote proxy is closed.

The following example shows a class extension that starts an assessment of the users' current progress and terminates the current playground when the always-on live view sends a message that it has finished the current task. Line 1 adds support for PlaygroundRemoteLiveViewProxyDelegate as an extension to the MyPlaygroundPageManager class. Lines 2-9 implement the method for receiving the message from the always-on live view. Lines 4 and 5 checks if “finishedTask” is true. Line 6 calls a custom function to update the user assessment, and line 7 terminates the current playground.

  1. extension MyPlaygroundPageManager: PlaygroundRemoteLiveViewProxyDelegate {
  2.    func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy,
  3.                             received message: PlaygroundValue) {
  4.       guard case let .dictionary(dict) = message else { return }
  5.       if case .boolean(_)? = dict["finishedTask"] {
  6.          updateAssessmentStatus()
  7.          PlaygroundPage.current.finishExecution()
  8.       }
  9.    }
  10. }

This example shows setting the proxy for a live view to a MyPlaygroundPageManager object.

  1. import PlaygroundSupport
  2. let proxy = PlaygroundPage.current.liveView as! PlaygroundRemoteLiveViewProxy
  3. let delegate = MyPlaygroundPageManager()
  4. proxy.delegate = delegate

Protocol Methods


Informs the handler that the connection between the proxy and the live view was closed.


  1. func remoteLiveViewProxyConnectionClosed(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy)


  • remoteLiveViewProxy: The live view connected to the proxy object.

remoteLiveViewProxy(_:, received:)

Allows the handler to receive a message from an always-on remote live view proxy.


  1. func remoteLiveViewProxy(_ remoteLiveViewProxy: PlaygroundRemoteLiveViewProxy, received message: PlaygroundValue)