Тёмный

How to use Global Actors in Swift (@globalActor) | Swift Concurrency #10 

Swiftful Thinking
Подписаться 50 тыс.
Просмотров 13 тыс.
50% 1

They are Actors... but global! In the last video we learned how to implement standard Actors in our applications. And while most of the time we do NOT need to make them GlobalActors, this is the perfect time to learn how to implement @globalActors... just in case! In this video we will go over a practical example of how to add them into your application. This allows you to isolate code that is not inside of an actor onto a global actor!
Next video: • What is the Sendable p...
Previous video: • How to use Actors and ...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-t...
DISCORD: / discord
GITHUB: github.com/Swi...
SAY THANKS: www.buymeacoff...

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 39   
@w0mblemania
@w0mblemania 6 месяцев назад
@16:19 According to the Swift Proposal, "A global actor type can be a struct, enum, actor, or final class. It is essentially just a marker type that provides access to the actual shared actor instance via shared".
@nurlankalybekov7336
@nurlankalybekov7336 2 месяца назад
It needs to get way more Thumbs up. Friends, 11K views and only 461 likes. More we give likes, more users will see such videos.
@lincolndickerson1293
@lincolndickerson1293 2 года назад
Since globalActors are by definition a single instance this leads me to believe they should be structs for access time reasons. Profile several use case or your particular use case may be the best answer here because there is a certain amount of optimizations going on internally. There was a WWDC video about this.
@hashcat5721
@hashcat5721 Год назад
Can you give me a link to this point at WWDC ?
@lincolndickerson1293
@lincolndickerson1293 Год назад
@@hashcat5721 I’ll what can find. My next few days are busy and since WWDC isnt fresh in my mind now its going to taking a bit of digging. In the mean time you may wantbto google WWDC GlobalActors, there cant be much out there on this.
@_sabot
@_sabot Год назад
This video explains well how the MainActor functionality is just built on top of the globalActor API, but with this simplistic example I've still no clue in which scenario I should create my own globalActor. Does anyone know a video or article with an more realistic example that clearly shows what problem this can solve?
@conorspalvieri5948
@conorspalvieri5948 2 года назад
I love your videos so much and there very useful. There is so little good tutorials on RU-vid, is there anyway you could make a video or two on implementing the camera in SwiftUI as a full screen.
@istuart0
@istuart0 11 дней назад
I'm becoming an intermediate Swift developer having followed your courses since January and written some fairly heavy apps. Now I'm starting to get my code Swift 6 ready, and learning more about actors, I'm wondering if, in the MVVM model, should all ViewModel classes be tagged at @MainActor?
@SwiftfulThinking
@SwiftfulThinking 11 дней назад
Yes, I would
@kdtechniquesofficial6153
@kdtechniquesofficial6153 Год назад
"The @MainActor attribute should be placed before the @Published property wrapper. " -ChatGPT-
@k3mehta
@k3mehta Год назад
Is there any reason why you can not/should not add @globalActor on MyNewDataManager and make it a singleton to avoid risking the issue you called out with multiple instances of it?
@lincolndickerson1293
@lincolndickerson1293 2 года назад
This has been a great series of videos as I have gotten used to enjoying from you. Having built several large apps there are certain things that are great candidates for global actors. In fact, most of the current singletons I use are to access a server somewhere and share the data throughout the app. Thanks for boiling this down to the essentials and presenting it so well.
@NathanQueija
@NathanQueija Год назад
Dude, thanks a lot for making these videos. The quality and curation of content are spot on.
@SwiftfulThinking
@SwiftfulThinking Год назад
You're welcome! Thanks for the comment.
@emirhan1356
@emirhan1356 Месяц назад
is @MainActor private lazy var mapView: MKMapView = { let mapView = MKMapView() mapView.translatesAutoresizingMaskIntoConstraints = false mapView.delegate = self mapView.showsCompass = false mapView.showsUserLocation = true return mapView }() this a valid usage? because it don't give any errors but also if I mark this with await, xcode warns me that no async process occurs
@lincolndickerson1293
@lincolndickerson1293 2 года назад
Paused at 17:50. For one time use actor MyNewDataManager I recommend putting it and MyFirstGlobalActor in the file and marking MyNewDataManager as fileprivate. That should keep it from being accidentally used.
@danielcrompton7818
@danielcrompton7818 2 месяца назад
7:54 this is incredibly confusing, why is it running on the main thread, it is async? And are you treating main actor = main thread?
@julienvignali1377
@julienvignali1377 Месяц назад
It is not running on the main thread. It's a mistake from the author. The viewModel.getData() method is awaited on a background thread. If the function, or the whole class was explicitly marked with @MainActor, then yeah, that would be running on the main thread and also blocking the UI.
@OlivierVanhamme
@OlivierVanhamme Год назад
Awesome content Nick! Regarding your question of whether to use a final class or structure for your singleton [16:50]? According to Stackoverflow answer 36788169 , classes are preferred to structures when working with singletons. One of the posts illustrates this with an example.
@santhoshVnair
@santhoshVnair 6 месяцев назад
Great series, very well explained. A question is have @10:50, globalactor must be singleton. @12:07, we are using a struct as globalactor and makes it singleton. I wonder why we use a struct (value type and not a reference type) as a singleton? Doesn't singleton negate the purpose of value type that can copy its value and make a new instance?
@cimoi2638
@cimoi2638 2 месяца назад
thank you so much for this whole playlist i was having a hard time understanding stuff but these are so well explained that i understand it now
@RandomNicknameOnYT
@RandomNicknameOnYT Год назад
16:50 What about using there`@globalActor actor MyNewDataManager { }` where init is private and all logic is in this actor? Isn't that a better solution?
@RedPPP
@RedPPP Год назад
A global actor can be a struct, enum, actor, or final class. (Source: SE-0316)
@kdtechniquesofficial6153
@kdtechniquesofficial6153 Год назад
Now I know how to use nonIsolated and Global Actors but I still don’t understand their use cases. 😢
@asadchattha3470
@asadchattha3470 6 месяцев назад
Thanks, Nick, for creating outstanding content.
@andresraigoza2082
@andresraigoza2082 Год назад
Every time I come to these videos I learn and understand more. Thank you so much Nick for these highly reliable videos.
@simply6162
@simply6162 Год назад
Why nick doesn’t like to use singleton he didn’t give a reason why. Can somebody tell me ?
@SwiftfulThinking
@SwiftfulThinking Год назад
Explained here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-E3x07blYvdE.html
@josemanuelortizsanchez4983
@josemanuelortizsanchez4983 Год назад
Thanks, this video is perfect to better understand the use of MainActor
@bruhmoment3731
@bruhmoment3731 2 года назад
Another excellent video. Can't wait to watch the last 2 videos
@indomitabletr1834
@indomitabletr1834 Год назад
awsome as always
@vlastos
@vlastos 2 года назад
Single Instance? Whats If I want to have separate instances per Account in a multi account app? Horrible api
@RobertMcGovernTarasis
@RobertMcGovernTarasis 8 месяцев назад
Can you explain further? What specifically is a horrible api? What would you propose as an alternative?
@w0mblemania
@w0mblemania 7 месяцев назад
In that case you would simply design a different class. There's a reason to use singletons (and reasons not to). It's YOUR job as a programmer to know how to apply the tools.
@KEVINKIM2586
@KEVINKIM2586 2 года назад
Thank you for these amazing series. Really helps me as a Junior iOS developer
@natgenesis5038
@natgenesis5038 Год назад
Do jr need this for entry level ?
@KEVINKIM2586
@KEVINKIM2586 Год назад
@@natgenesis5038 none of the interviews asked me about global actors. But not bad to know I guess
@gilbertandreifloarea719
@gilbertandreifloarea719 2 года назад
First
@veens.m
@veens.m 2 года назад
Good Boy 👏🏼
Далее
+1000 Aura For This Save! 🥵
00:19
Просмотров 12 млн
Дикий Бармалей разозлил всех!
01:00
Week 3 - Part 2 Counselling Theory
30:28
How do Actors work in Swift?
19:05
Просмотров 4,1 тыс.
Actor Reentrancy in Swift explained
20:18
Просмотров 2 тыс.
+1000 Aura For This Save! 🥵
00:19
Просмотров 12 млн