File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// Some tips before starts
22Prefer Value Types ( Structs) When Possible
33Value 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
You can’t perform that action at this time.
0 commit comments