-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathrdar91150414.swift
69 lines (54 loc) · 1.18 KB
/
rdar91150414.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
// REQUIRES: objc_interop
// REQUIRES: OS=macosx
import SwiftUI
import Foundation
protocol P {
var info: Info? { get }
}
protocol Q : P {
func makeView() -> AnyView
}
struct Info {
var kind: Kind
var size: CGSize { fatalError() }
}
enum Kind {
case supported([Int])
case unsupported
}
struct Settings {
var setting = Setting.defaultValue
}
struct Setting {
static let defaultValue = Setting()
func scale(_: CGFloat) -> Setting {
fatalError()
}
func scale(_: CGSize) -> CGSize {
fatalError()
}
}
struct Test: View {
var res: P
var enable: Bool
var settings: Settings
var body: some View {
if let result = res as? Q {
let view = result.makeView()
if let info = result.info {
let show: Bool = {
guard enable else { return false }
switch info.kind {
case .supported: return true
case .unsupported: return false
}
}()
if show {
let size = settings.setting.scale(info.size)
view.frame(width: size.width, height: size.height)
}
}
}
}
}