bro you are amazing Edit: Also sendable acts as a guard for future safery thread checks, is someone ads a var to a sendable without being aware its being used in asyc sendable will alert them.
At 15.00, should that not be a queue.sync? I'm confused whether it should be async or sync. I believe that if you're making it thread-safe, you need to use sync
We almost always want async, since sync can block the thread. In practice, we almost never need to write this code anymore, since we will use Actors instead.
Awesommmmmme Video! Thank you so much fore great video! A huge Salute to you 999999999999 times! Keep sharing your knowledge & making awesome video! genius!
Trying to think of a case that a final class would be needed where a struct or actor couldn’t fit the bill. In the unchecked sendable case shown in the video all we are really doing making an understudy, weak actor, aka an novice implementation of thread safe class? What am I missing?
as i said before about mutating.. you must be careful. struct MyStruct: Sendable { var title: String mutating func changeTitle(newTitle: String) { title = newTitle } func unsafe( t: inout MyStruct) { t.changeTitle(newTitle: "new title") } func test() { var t = MyStruct(title: "hello") unsafe(t: &t) print(t.title) } }
@@SwiftfulThinking Actually, I was wrong. When you try to run a mutating struct function in a thread context, you will get an error saying 'Escaping closure captures mutating 'self' parameter.' So, I guess it is not that structs are thread-safe; they just cannot be shared between threads (which is logical, as most structs are created on the stack). Swift is smart, unlike C++, it will not let you do crazy things.
8:41 - In xCode 14.1 there will only be a warning and not an error.
Update: I think in Swift 6 it will become an error, for now just a warning
bro you are amazing
Edit: Also sendable acts as a guard for future safery thread checks, is someone ads a var to a sendable without being aware its being used in asyc sendable will alert them.
Thank you as always for your great work Nick!
Amazing tutorial.Crystal clear.
At 15.00, should that not be a queue.sync? I'm confused whether it should be async or sync. I believe that if you're making it thread-safe, you need to use sync
We almost always want async, since sync can block the thread. In practice, we almost never need to write this code anymore, since we will use Actors instead.
I feel like it should be sync too. What if getting name function works before updateName. If we make both sync we ll be sure of the execution order
Awesome as always. Thank you so much!!!
Your videos are great, do you have a plan to cover Transferable
Awesommmmmme Video! Thank you so much fore great video! A huge Salute to you 999999999999 times! Keep sharing your knowledge & making awesome video! genius!
What is the brand of your keyboard that sound is very impress me
That is a 16” MacBook Pro 😂
@@SwiftfulThinking omg 😱
Great video, thanks!
Trying to think of a case that a final class would be needed where a struct or actor couldn’t fit the bill. In the unchecked sendable case shown in the video all we are really doing making an understudy, weak actor, aka an novice implementation of thread safe class? What am I missing?
hey vro ...how to make Core Data Entities conforming to Sendable??
Cool!
as i said before about mutating.. you must be careful.
struct MyStruct: Sendable {
var title: String
mutating func changeTitle(newTitle: String) {
title = newTitle
}
func unsafe( t: inout MyStruct) {
t.changeTitle(newTitle: "new title")
}
func test() {
var t = MyStruct(title: "hello")
unsafe(t: &t)
print(t.title)
}
}
This obviously isn't thread-safe.
@@alexvaiman4966yea I guess I should have been more clear about immutable structs vs mutable structs too
@@SwiftfulThinking Actually, I was wrong. When you try to run a mutating struct function in a thread context, you will get an error saying 'Escaping closure captures mutating 'self' parameter.' So, I guess it is not that structs are thread-safe; they just cannot be shared between threads (which is logical, as most structs are created on the stack). Swift is smart, unlike C++, it will not let you do crazy things.