-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-view-structure.swift
More file actions
89 lines (71 loc) · 1.82 KB
/
test-view-structure.swift
File metadata and controls
89 lines (71 loc) · 1.82 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import SwiftUI
/// Test 1: Computed property before body (SHOULD violate - computed must be after body)
struct TestComputedBeforeBody: View {
@State private var count: Int = 0
private var config: String {
"computed value"
}
var body: some View {
Text(config)
}
}
/// Test 2: Computed property after body (should NOT violate)
struct TestComputedAfterBody: View {
@State private var count: Int = 0
var body: some View {
Text(computed)
}
private var computed: String {
"value"
}
}
/// Test 3: ViewBuilder computed property (should NOT violate)
struct TestViewBuilderComputed: View {
var body: some View {
VStack {
headerSection
}
}
@ViewBuilder private var headerSection: some View {
Text("Header")
Text("Subtitle")
}
}
/// Test 4: Multiple computed properties (should NOT violate)
struct TestMultipleComputed: View {
let grayscaleImage: Int?
@Binding var strategy: String
var body: some View {
VStack {
header
content
}
}
@ViewBuilder private var content: some View {
if let grayscaleImage {
Text("\(grayscaleImage)")
}
}
private var header: some View {
Text("Header")
}
}
/// Test 5: Stored property after body (SHOULD violate)
struct TestStoredAfterBody: View {
var body: some View {
Text("Hello")
}
/// This SHOULD violate - stored property after body
@State private var count: Int = 0
}
/// Test 6: Correct order (should NOT violate) - stored → body → computed
struct TestCorrectOrder: View {
@State private var count: Int = 0
var body: some View {
Text("Hello")
}
private var computed: String {
"value"
}
}
class AppState: ObservableObject {}