Skip to content

Commit 4494b66

Browse files
Update MigrationGuideSwift6.swift
1 parent e808579 commit 4494b66

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

SwiftUIExamples/MigrationGuideSwift6.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Some tips before starts
22
Prefer Value Types (Structs) When Possible
33
Value types are copied when passed around, reducing the risk of shared mutable state.
4+
45
// MARK: Example 1
56
/*class HomeViewController {
67

@@ -125,5 +126,30 @@ class CartView {
125126

126127
}
127128

129+
// MARK: Example #5 Accessing Non-Sendable Types Across Threads
130+
class SongClass {
131+
var data: String = ""
132+
133+
func update() {
134+
DispatchQueue.global().async {
135+
// Warning here Capture of 'self' with non-sendable type 'SongClass' in a '@Sendable' closure
136+
// Warning Class 'SongClass' does not conform to the 'Sendable' protocol
137+
self.data.append("New")
138+
}
139+
}
140+
}
141+
142+
actor SongClassFixed {
143+
private var data = ""
144+
145+
func append(_ value: String) {
146+
data.append(value)
147+
}
148+
149+
func getData() -> String {
150+
return data
151+
}
152+
}
153+
128154

129155

0 commit comments

Comments
 (0)