File tree Expand file tree Collapse file tree 5 files changed +62
-6
lines changed Expand file tree Collapse file tree 5 files changed +62
-6
lines changed Original file line number Diff line number Diff line change 13
13
import Foundation
14
14
@_exported import AppKit
15
15
16
- extension NSCursor : CustomPlaygroundQuickLookable {
17
- public var customPlaygroundQuickLook : PlaygroundQuickLook {
16
+ extension NSCursor : _DefaultCustomPlaygroundQuickLookable {
17
+ public var _defaultCustomPlaygroundQuickLook : PlaygroundQuickLook {
18
18
return . image( image)
19
19
}
20
20
}
@@ -23,8 +23,8 @@ internal struct _NSViewQuickLookState {
23
23
static var views = Set < NSView > ( )
24
24
}
25
25
26
- extension NSView : CustomPlaygroundQuickLookable {
27
- public var customPlaygroundQuickLook : PlaygroundQuickLook {
26
+ extension NSView : _DefaultCustomPlaygroundQuickLookable {
27
+ public var _defaultCustomPlaygroundQuickLook : PlaygroundQuickLook {
28
28
// if you set NSView.needsDisplay, you can get yourself in a recursive scenario where the same view
29
29
// could need to draw itself in order to get a QLObject for itself, which in turn if your code was
30
30
// instrumented to log on-draw, would cause yourself to get back here and so on and so forth
Original file line number Diff line number Diff line change @@ -187,8 +187,8 @@ internal struct _UIViewQuickLookState {
187
187
static var views = Set < UIView > ( )
188
188
}
189
189
190
- extension UIView : CustomPlaygroundQuickLookable {
191
- public var customPlaygroundQuickLook : PlaygroundQuickLook {
190
+ extension UIView : _DefaultCustomPlaygroundQuickLookable {
191
+ public var _defaultCustomPlaygroundQuickLook : PlaygroundQuickLook {
192
192
if _UIViewQuickLookState. views. contains ( self ) {
193
193
return . view( UIImage ( ) )
194
194
} else {
Original file line number Diff line number Diff line change @@ -697,6 +697,9 @@ extension PlaygroundQuickLook {
697
697
if let customized = subject as? CustomPlaygroundQuickLookable {
698
698
self = customized. customPlaygroundQuickLook
699
699
}
700
+ else if let customized = subject as? _DefaultCustomPlaygroundQuickLookable {
701
+ self = customized. _defaultCustomPlaygroundQuickLook
702
+ }
700
703
else {
701
704
if let q = _reflect ( subject) . quickLookObject {
702
705
self = q
@@ -723,6 +726,13 @@ public protocol CustomPlaygroundQuickLookable {
723
726
var customPlaygroundQuickLook : PlaygroundQuickLook { get }
724
727
}
725
728
729
+
730
+ // A workaround for <rdar://problem/25971264>
731
+ // FIXME(ABI)
732
+ public protocol _DefaultCustomPlaygroundQuickLookable {
733
+ var _defaultCustomPlaygroundQuickLook : PlaygroundQuickLook { get }
734
+ }
735
+
726
736
//===--- General Utilities ------------------------------------------------===//
727
737
// This component could stand alone, but is used in Mirror's public interface.
728
738
Original file line number Diff line number Diff line change @@ -730,6 +730,35 @@ mirrors.test("PlaygroundQuickLook") {
730
730
}
731
731
}
732
732
733
+ class Parent { }
734
+
735
+ extension Parent : _DefaultCustomPlaygroundQuickLookable {
736
+ var _defaultCustomPlaygroundQuickLook : PlaygroundQuickLook {
737
+ return . text( " base " )
738
+ }
739
+ }
740
+
741
+ class Child : Parent { }
742
+
743
+ class FancyChild : Parent , CustomPlaygroundQuickLookable {
744
+ var customPlaygroundQuickLook : PlaygroundQuickLook {
745
+ return . text( " child " )
746
+ }
747
+ }
748
+
749
+ mirrors. test ( " _DefaultCustomPlaygroundQuickLookable " ) {
750
+ // testing the workaround for custom quicklookables in subclasses
751
+ switch PlaygroundQuickLook ( reflecting: Child ( ) ) {
752
+ case . text( " base " ) : break
753
+ default : expectUnreachable ( " Base custom quicklookable was expected " )
754
+ }
755
+
756
+ switch PlaygroundQuickLook ( reflecting: FancyChild ( ) ) {
757
+ case . text( " child " ) : break
758
+ default : expectUnreachable ( " FancyChild custom quicklookable was expected " )
759
+ }
760
+ }
761
+
733
762
import MirrorObjC
734
763
mirrors. test ( " ObjC " ) {
735
764
// Some Foundation classes lie about their ivars, which would crash
Original file line number Diff line number Diff line change @@ -78,4 +78,21 @@ UIKitTests.test("UIOffset") {
78
78
checkEquatable ( offsets, oracle: { $0 == $1 } )
79
79
}
80
80
81
+ class TestChildView : UIView , CustomPlaygroundQuickLookable {
82
+ convenience init ( ) {
83
+ self . init ( frame: CGRect ( x: 0 , y: 0 , width: 10 , height: 10 ) )
84
+ }
85
+ var customPlaygroundQuickLook : PlaygroundQuickLook {
86
+ return . text( " child " )
87
+ }
88
+ }
89
+
90
+ UIKitTests . test ( " CustomPlaygroundQuickLookable " ) {
91
+ switch PlaygroundQuickLook ( reflecting: TestChildView ( ) ) {
92
+ case . text( " child " ) : break
93
+ default : expectUnreachable (
94
+ " TestChildView custom quicklookable should have been invoked " )
95
+ }
96
+ }
97
+
81
98
runAllTests ( )
You can’t perform that action at this time.
0 commit comments