Skip to content

Commit 5345128

Browse files
author
Max Moiseev
committed
[stdlib] workaround for CustomPlaygroundQuickLookable in UIView subclasses
1 parent 9c65461 commit 5345128

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

stdlib/public/SDK/AppKit/AppKit.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import Foundation
1414
@_exported import AppKit
1515

16-
extension NSCursor : CustomPlaygroundQuickLookable {
17-
public var customPlaygroundQuickLook: PlaygroundQuickLook {
16+
extension NSCursor : _DefaultCustomPlaygroundQuickLookable {
17+
public var _defaultCustomPlaygroundQuickLook: PlaygroundQuickLook {
1818
return .image(image)
1919
}
2020
}
@@ -23,8 +23,8 @@ internal struct _NSViewQuickLookState {
2323
static var views = Set<NSView>()
2424
}
2525

26-
extension NSView : CustomPlaygroundQuickLookable {
27-
public var customPlaygroundQuickLook: PlaygroundQuickLook {
26+
extension NSView : _DefaultCustomPlaygroundQuickLookable {
27+
public var _defaultCustomPlaygroundQuickLook: PlaygroundQuickLook {
2828
// if you set NSView.needsDisplay, you can get yourself in a recursive scenario where the same view
2929
// could need to draw itself in order to get a QLObject for itself, which in turn if your code was
3030
// instrumented to log on-draw, would cause yourself to get back here and so on and so forth

stdlib/public/SDK/UIKit/UIKit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ internal struct _UIViewQuickLookState {
187187
static var views = Set<UIView>()
188188
}
189189

190-
extension UIView : CustomPlaygroundQuickLookable {
191-
public var customPlaygroundQuickLook: PlaygroundQuickLook {
190+
extension UIView : _DefaultCustomPlaygroundQuickLookable {
191+
public var _defaultCustomPlaygroundQuickLook: PlaygroundQuickLook {
192192
if _UIViewQuickLookState.views.contains(self) {
193193
return .view(UIImage())
194194
} else {

stdlib/public/core/Mirror.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ extension PlaygroundQuickLook {
697697
if let customized = subject as? CustomPlaygroundQuickLookable {
698698
self = customized.customPlaygroundQuickLook
699699
}
700+
else if let customized = subject as? _DefaultCustomPlaygroundQuickLookable {
701+
self = customized._defaultCustomPlaygroundQuickLook
702+
}
700703
else {
701704
if let q = _reflect(subject).quickLookObject {
702705
self = q
@@ -723,6 +726,13 @@ public protocol CustomPlaygroundQuickLookable {
723726
var customPlaygroundQuickLook: PlaygroundQuickLook { get }
724727
}
725728

729+
730+
// A workaround for <rdar://problem/25971264>
731+
// FIXME(ABI)
732+
public protocol _DefaultCustomPlaygroundQuickLookable {
733+
var _defaultCustomPlaygroundQuickLook: PlaygroundQuickLook { get }
734+
}
735+
726736
//===--- General Utilities ------------------------------------------------===//
727737
// This component could stand alone, but is used in Mirror's public interface.
728738

test/1_stdlib/Mirror.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,35 @@ mirrors.test("PlaygroundQuickLook") {
730730
}
731731
}
732732

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+
733762
import MirrorObjC
734763
mirrors.test("ObjC") {
735764
// Some Foundation classes lie about their ivars, which would crash

test/1_stdlib/UIKit.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,21 @@ UIKitTests.test("UIOffset") {
7878
checkEquatable(offsets, oracle: { $0 == $1 })
7979
}
8080

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+
8198
runAllTests()

0 commit comments

Comments
 (0)