In my code i am displaying the message on tableView in ios swift uikit using actor, the table view delegate methods will call synchronously but the data from actor isolated property i am getting using Task method with in that tableview delegates synchronous execution, now the problem is the tableview delegates method synchronous execution is not waiting for the Task method to complete await function, can any one suggest on this please
Hey pallev, Thanks for the video. Have one question why you used sync on both operations with barrier.I think same could be achieved without using barrier on sync operation (as they already in sync)or async operation with barrier?
Use sync function for read to block current thread, while using async function with barrier flag for write to return to current queue. This is good for when multiple reads is preferred when there is no write.
And chance this is usable also for communication between realtime audio thread and main thread ? I mean if you are trying to communicated between realtime audio thread and main thread there are some forbidden things like using of MUTEX - so any chance all this Actors aren’t using MUTEX ?
Great tutorial. I observed that even when I did not create add keyword "MainActor" and just called the updateLabel method from my Task block, I did NOT get a crash and the setting up the break point inside updateLabel showed that it was on main thread. How is that possible?
Sorry dear i would like to correct you... why you are blocking the queue using sync operation, you must use barrier flag on concurrent queue with async operation always.
Interesting trade off. The barrier was neat in the old Flight class. Now the burden to make it properly called, the caller are forced to call with async await.
Hi Pallav, Great fan of yours. In a couple of interviews, I faced this question. "How do you convert struct to a class? or atleast give some functionalities of class to struct." I searched a lot through web but couldn't find any answer. Could you please help me with this.
TBH, it's not a very good question from the interviewer. I guess they could be trying to make you think, but still, not a useful question. The only good response I would give is "what, exactly, do you want your class to do"? And then explain the differences between structs and classes, and why you don't actually want to be "converting" structs to classes.
Mostly, when you have guarantee that the object won't be nil, unowned can be used. Otherwise, prefer weak to be safe. There are other details too.. I'll try covering them in the video that I'll do weak, unowned etc. Thanks for the suggestion 🙂
@@iCode_Happy_Coding I think if i will follow your videos, will become master certainly. Please guide us how to prepare DSA for beginner to expert level and then solve interview’s online test with all test cases. I have seen some UA-cam lectures but i need something that covert step by step and all content should have at single place. I am rejected 10 times from Nagarro and other reputed company’s online test. Thank you
Hey pallev, Thanks for this great video. now I have a clear concept of Actor. I would really appreciate if you can come up with one video of Closures. thanks
Hi Pallav, Thanks for the video. I tried with same approach but surprisingly it worked if I used the 2 queue like in your video but whenever I tried with 3 queue it is not working. I am sharing the code snippet for the same. Share your thought on it. actor Flight { var availableSeats = ["1A", "2B", "3C"] func bookSeat() -> String { let bookedSeat = availableSeats.first ?? "" availableSeats.removeFirst() return bookedSeat } func getAvailableSeats() -> [String] { availableSeats } } class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let flight = Flight() let queue1 = DispatchQueue(label: "queue1") let queue2 = DispatchQueue(label: "queue2") let queue3 = DispatchQueue(label: "queue3") queue1.async { Task { let availableSeats = await flight.getAvailableSeats() print("Available seats \(availableSeats)") } } queue2.async { Task { let bookedSeat = await flight.bookSeat() print("Booked seat \(bookedSeat)") } } queue3.async { Task { let availableSeats = await flight.getAvailableSeats() print("Available seats after booking \(availableSeats)") } } } }
Why do you think this didn't work? It works for me. I get Booked seat 1A Available seats after booking ["2B", "3C"] Available seats ["2B", "3C"] In the console, which is what I would expect. Only one task is booking, the others are waiting, then printing the available seats.
You explained simply and clearly about Actors. Good Work..
Why writing Task in DispatchQueue ? Also 5:31 why we want to halt the main. thread via using `sync` instead of `async` , is it just to return value?
Hey, thanks so much! Why are the queues at the end still needed? Or if they aren't needed, why are you still using them?
You have great didactic abilities … bravo from 🇨🇭
Awesome video. Thanks for sharing your knowledge. Helps a lot
Very well explained. Keep up the good work.
Thanks for the kind words 🙂
Actor concept is Nice , it's really interesting, compare to existing techniques.
Awesome awesome explanation brother 🤩🤩. Thank you so much for your all videos 😍
In my code i am displaying the message on tableView in ios swift uikit using actor, the table view delegate methods will call synchronously but the data from actor isolated property i am getting using Task method with in that tableview delegates synchronous execution, now the problem is the tableview delegates method synchronous execution is not waiting for the Task method to complete await function, can any one suggest on this please
well done very nice explanation 👍
Hey pallev,
Thanks for the video.
Have one question why you used sync on both operations with barrier.I think same could be achieved without using barrier on sync operation (as they already in sync)or async operation with barrier?
Use sync function for read to block current thread, while using async function with barrier flag for write to return to current queue. This is good for when multiple reads is preferred when there is no write.
Very nice explanation.
Thanks Yogesh 🙂
Learnt something new today. Thank you. What I am more curious about is how the actor is working internally?
Superb keep posting💪
Sure 🙂
And chance this is usable also for communication between realtime audio thread and main thread ? I mean if you are trying to communicated between realtime audio thread and main thread there are some forbidden things like using of MUTEX - so any chance all this Actors aren’t using MUTEX ?
Thank you for nice content.
Thank you for awesome video !!!
Great tutorial. I observed that even when I did not create add keyword "MainActor" and just called the updateLabel method from my Task block, I did NOT get a crash and the setting up the break point inside updateLabel showed that it was on main thread. How is that possible?
Sorry dear i would like to correct you... why you are blocking the queue using sync operation, you must use barrier flag on concurrent queue with async operation always.
Interesting trade off. The barrier was neat in the old Flight class. Now the burden to make it properly called, the caller are forced to call with async await.
Hi Pallav,
Great fan of yours. In a couple of interviews, I faced this question. "How do you convert struct to a class? or atleast give some functionalities of class to struct." I searched a lot through web but couldn't find any answer. Could you please help me with this.
TBH, it's not a very good question from the interviewer.
I guess they could be trying to make you think, but still, not a useful question.
The only good response I would give is "what, exactly, do you want your class to do"?
And then explain the differences between structs and classes, and why you don't actually want to be "converting" structs to classes.
Thanks Palav
Nice explanation 👍
Thanks 🙂
Thankssssss....😍😍😍
When should we use weak and unowned in swift?
Mostly, when you have guarantee that the object won't be nil, unowned can be used. Otherwise, prefer weak to be safe. There are other details too.. I'll try covering them in the video that I'll do weak, unowned etc. Thanks for the suggestion 🙂
@@iCode_Happy_Coding I think if i will follow your videos, will become master certainly. Please guide us how to prepare DSA for beginner to expert level and then solve interview’s online test with all test cases. I have seen some UA-cam lectures but i need something that covert step by step and all content should have at single place.
I am rejected 10 times from Nagarro and other reputed company’s online test.
Thank you
Great Job 👏
Thanks Akshay 🙂
Hey pallev,
Thanks for this great video. now I have a clear concept of Actor. I would really appreciate if you can come up with one video of Closures. thanks
Thank you
Impressive ....once again.👏👏👏
superbb
Thanks for the nice content
Very nice sir. thanks
I learnt the latest topic. Thanks for sharing.
🎉🎉🎉🎉❤
thanks for the video keep up the good work :)
Thank you for sharing the valuable information
Glad that you found it useful 🙂
Thanks for this lesson)))
👍
Hi Pallav,
Thanks for the video.
I tried with same approach but surprisingly it worked if I used the 2 queue like in your video but whenever I tried with 3 queue it is not working. I am sharing the code snippet for the same. Share your thought on it.
actor Flight {
var availableSeats = ["1A", "2B", "3C"]
func bookSeat() -> String {
let bookedSeat = availableSeats.first ?? ""
availableSeats.removeFirst()
return bookedSeat
}
func getAvailableSeats() -> [String] {
availableSeats
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let flight = Flight()
let queue1 = DispatchQueue(label: "queue1")
let queue2 = DispatchQueue(label: "queue2")
let queue3 = DispatchQueue(label: "queue3")
queue1.async {
Task {
let availableSeats = await flight.getAvailableSeats()
print("Available seats \(availableSeats)")
}
}
queue2.async {
Task {
let bookedSeat = await flight.bookSeat()
print("Booked seat \(bookedSeat)")
}
}
queue3.async {
Task {
let availableSeats = await flight.getAvailableSeats()
print("Available seats after booking \(availableSeats)")
}
}
}
}
Why do you think this didn't work? It works for me. I get
Booked seat 1A
Available seats after booking ["2B", "3C"]
Available seats ["2B", "3C"]
In the console, which is what I would expect. Only one task is booking, the others are waiting, then printing the available seats.
@@joshuawalker7530 Can you run 5 times and check you are getting the same results, Its not working for me as well with actor giving different results