1
+ //===--- PlaygroundDisplay.swift ------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift.org open source project
4
+ //
5
+ // Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
+ //
11
+ //===----------------------------------------------------------------------===//
12
+
13
+ /// A type that supplies a custom description for playground logging.
14
+ ///
15
+ /// All types have a default description for playgrounds. This protocol
16
+ /// allows types to provide custom descriptions which are then logged in
17
+ /// place of the original instance.
18
+ ///
19
+ /// Playground logging can generate, at a minimum, a structured description
20
+ /// of any type. Playground logging is also capable of generating a richer,
21
+ /// more specialized description of core types -- for instance, the contents
22
+ /// of a `String` are logged, as are the components of an `NSColor` or
23
+ /// `UIColor`.
24
+ ///
25
+ /// The current playground logging implementation logs specialized
26
+ /// descriptions of at least the following types:
27
+ ///
28
+ /// - `String` and `NSString`
29
+ /// - `Int` and `UInt` (including the sized variants)
30
+ /// - `Float` and `Double`
31
+ /// - `Bool`
32
+ /// - `Date` and `NSDate`
33
+ /// - `NSAttributedString`
34
+ /// - `NSNumber`
35
+ /// - `NSRange`
36
+ /// - `URL` and `NSURL`
37
+ /// - `CGPoint`, `CGSize`, and `CGRect`
38
+ /// - `NSColor`, `UIColor`, `CGColor`, and `CIColor`
39
+ /// - `NSImage`, `UIImage`, `CGImage`, and `CIImage`
40
+ /// - `NSBezierPath` and `UIBezierPath`
41
+ /// - `NSView` and `UIView`
42
+ ///
43
+ /// Playground logging may also be able to support specialized descriptions
44
+ /// of other types.
45
+ ///
46
+ /// Implementors of `CustomPlaygroundDisplayConvertible` may return a value of
47
+ /// one of the above types to also receive a specialized log description.
48
+ /// Implementors may also return any other type, and playground logging will
49
+ /// generated structured logging for the returned value.
50
+ ///
51
+ /// - note: `CustomPlaygroundDisplayConvertible` conformances chain -- that is,
52
+ /// if `playgroundDescription` returns an instance which itself conforms to
53
+ /// `CustomPlaygroundDisplayConvertible`, then playground logging will ask for
54
+ /// that instance's `playgroundDescription` and so on. It is permissible for
55
+ /// playground logging implementations to place a reasonable limit on this
56
+ /// kind of chaining to prevent infinite loops.
57
+ public protocol CustomPlaygroundDisplayConvertible {
58
+ /// Returns the custom playground description for this instance.
59
+ ///
60
+ /// If this type has value semantics, the instance returned should be
61
+ /// unaffected by subsequent mutations if possible.
62
+ var playgroundDescription : Any { get }
63
+ }
0 commit comments