iOS Concurrency and Threading - iOS Interview Question - Swift

  Переглядів 104,842

Sean Allen

Sean Allen

6 років тому

The next topic in my series on iOS Interview questions explains concurrency and threading in iOS and Swift. This iOS interview question was asked in quite a few interviews. In this concurrency and threading tutorial I explain what is going on at a high level to help you answer this interview question.
iOS Dev Courses - seanallen.teachable.com/
This is part of a series of videos about iOS interview questions in Swift. Check out the overview where I list and briefly discuss all the topics that are in this series:
• iOS Interview Question...
Twitter:
Sean Allen - / seanallen_dev
Hired.com:
hired.com/x/1n01g
Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):
Paul Hudson's Hacking With Swift:
gumroad.com/a/762098803
Donny Wals - Combine:
gumroad.com/a/909014131
Mark Moeyken’s SwiftUI Books:
www.bigmountainstudio.com/swiftui-views-book/fzc51
Objc.io Books (Thinking in SwiftUI & Advanced Swift):
gumroad.com/a/656585843
Ray Wenderlich Books:
store.raywenderlich.com/a/208...
#swift #softwaredeveloper #iosdeveloper

КОМЕНТАРІ: 202
@seanallen
@seanallen 4 роки тому
Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ukposts.info/have/v-deo/hYN6mWiwbXyWxmw.html
@pawelpow
@pawelpow 2 роки тому
The car highway analogy is the best one I’ve heard so far. You are awesome! You always provide the best explanations
@bibinjaimon
@bibinjaimon 3 роки тому
I've seen this video 3 years ago. Now again came here to recollect things. Thanks for making this video🙂
@rungxanh2901
@rungxanh2901 3 роки тому
Such an intuitive approach to learn about concurrency and thread. Thank you Sean 🙌🏻
@hariharanjagan404
@hariharanjagan404 4 роки тому
i have 8 years of experience in iOS and you videos are simple & great examples
@richardgmartinonline
@richardgmartinonline 6 років тому
Hi Sean: Job well done. You obviously put quite a bit of time into this video. The explanation is very clear and understandable.
@seanallen
@seanallen 6 років тому
Thanks Richard, yeah... this was one tough to put together, but I think it turned out ok.
@batuhankrbb
@batuhankrbb 3 роки тому
I just want to tell you that you are rock! I really love your courses, videos and contents. Keep going
@wensmusic8636
@wensmusic8636 2 роки тому
Dude you are an amazing teacher. I really enjoy your teach style, you bring real life examples into code and that really helps with bringing things into perspective. Thank you for taking your time out to teach us all of this. I have an interview tomorrow and I feel so much better now that i've seen your series and I know that i'm hitting on the right topics and that I actually understand them. Thank you bro
@seanallen
@seanallen 2 роки тому
Happy to help. Glad you enjoyed the series!
@dre5671
@dre5671 2 роки тому
Good luck! Hope it went well!
@candylover2456
@candylover2456 3 роки тому
Love your videos! Thanks so much :D Do you have videos on MVC, MVVM, and other patterns? If not, can you please make a video on those topics?
@beastgenv
@beastgenv 6 років тому
That was pretty solid explanation once again, I have been learning iOS Development for the past 6 months now and watched almost all of you videos, great work. Every time I learn at least a thing I did not know before. Thank you.
@seanallen
@seanallen 6 років тому
Glad you learned something, Alisher! Thanks for watching.
@wanted47
@wanted47 5 років тому
I’m listening to this while I’m on my way to a technical interview after learning iOS Development for almost a year with zero coding background. Great stuff Sean!
@seanallen
@seanallen 5 років тому
Good luck on the interview!
@wanted47
@wanted47 5 років тому
@@seanallenThank you very much Sean. I got the job!!! Looking forward to sharing my story on how I became an iOS dev within a year :D
@seanallen
@seanallen 5 років тому
That's awesome! Congrats!
@dodilodi1278
@dodilodi1278 2 роки тому
@@wanted47 where is your story :D
@messilicious4045
@messilicious4045 Рік тому
He got busy developing stuff..#nostory
@quyetbuihuu1599
@quyetbuihuu1599 5 років тому
thank you. I learned a lot from this video
@shadow16g
@shadow16g 4 роки тому
Hi Sean, Thanks again for this tutorials, they are very helpful. I will have an interview soon and I am concerned they may ask whats the difference between Dispatch Queue and NSOperations. Can you share some light :D
@MarcosFelipejchrist
@MarcosFelipejchrist 6 років тому
Thanks for video . Its the best video about GCD I've ever seen. The video is excellent , audio is great and you can show with animations and codes. You're doing the fantastic work. Congratulations for your work
@seanallen
@seanallen 6 років тому
Thanks Marcos! This is one of my favorite videos that I've made. Glad you liked it!
@atom2ueki
@atom2ueki 6 років тому
A lot of developers don't have a strong basic knowledge now days and this kind of videos really helps, appreciate it, like your videos, thanks man and keep going!
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Tony!
@andreadavid5113
@andreadavid5113 4 роки тому
Hey Sean, such an excellent explanation for me as a beginner developer. I wasn't expect that you use a lot of some kind of real-life example like the highway and the queue but you did, so that's nice and very much easy to understand compared to coding. Thank you very much and keep up the good works!
@seanallen
@seanallen 4 роки тому
Thanks for the kind words. Happy hear you enjoyed the explanation 😀
@dexteritylord1725
@dexteritylord1725 2 роки тому
Thank you for simplifying this.
@israman30
@israman30 6 років тому
This is a really good tutorial about concurrency. Thanks Sean.., great job.!!
@seanallen
@seanallen 6 років тому
Thanks Patrick!
@raousama4276
@raousama4276 4 роки тому
you explained all this in a very simple manner...good job done
@seanallen
@seanallen 4 роки тому
Thanks! Glad you liked it.
@mrmillmill
@mrmillmill 2 роки тому
Great videos! I enjoy your paid courses as well! Very thorough and well executed Sean. Question: what are a list of tasks that happen on background threads vs a list of tasks that happen on main thread? My understanding is closures occur on a background thread and updating UI happen on main thread. Any other logic, tasks, methods etc that directly link to background thread or main thread? Basically, what are the dead giveaways in code that state,”This is background thread or main thread?” Also, what allows you to see what thread something is occurring on? Is there code that will reveal that? Like code for checking type(of:) for data types tells the data type…is there something similar to understand which thread is used for code?
@marinaaguiar5444
@marinaaguiar5444 2 роки тому
wow Sean!! thanks so much for this video! it really cleared up my mind about this topic =) you've done an amazing job with this well didactic tutorial
@genebogdanovich972
@genebogdanovich972 6 років тому
Sean, thank you for making these videos! Keep it up!
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, Gene!
@Emad-mc9uh
@Emad-mc9uh 4 роки тому
thanks mate
@seanallen
@seanallen 4 роки тому
Thanks! Glad you liked it!
@vandanpatel3395
@vandanpatel3395 6 років тому
Great explanation, Sean. You are right that this is a tricky topic, but whatever you have mentioned in the video, it's more than enough for an iOS Developer to work on Apps.
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Vandan. It was hard to figure out how to present this topic in the best way. Hope everyone likes it!
@thatmark88
@thatmark88 6 років тому
Great explain, especially the high way example, but what's the different between queues and thread? Seems they are doing the same purpose of concurrent queue and mutiple-thread...
@filipsardjoski
@filipsardjoski 6 років тому
Excellent work! Animation and visual explanation helps a ton 😊
@seanallen
@seanallen 6 років тому
Thanks Filip! Glad you like it.
@weepingwillow2056
@weepingwillow2056 2 роки тому
In most cases you embed the switching to the main thread inside the background queue so you call and out layer asych and inside of it a switch to main queue asynch to update UI.
@adeadegoke4925
@adeadegoke4925 6 років тому
I am upset that 2 people have disliked this tutorial. I can not understand why. Anyway another great tutorial Sean. Keep it up
@seanallen
@seanallen 6 років тому
Haha, can't please them all, I guess... Thanks for the kind words, Ade!
@lujonghao
@lujonghao 6 років тому
It has something to do with the Star Wars I guess
@RyuuzakiJulio
@RyuuzakiJulio 5 років тому
Maybe they wanted an actual working sample code and not the same animations running 20 times and someone typing something and not just talking to the camera?
@seanallen
@seanallen 5 років тому
??? I don’t even know which video of mine this is referring to. The creator app doesn’t show me. I just know it’s an older video.
@seanallen
@seanallen 5 років тому
Thanks for the link. Julio misinterpreted the point of the video. This is part of my interview question playlist on how to answer questions you’ll be asked. When on phone screens for interviews they won’t ask you to code this kind of stuff. They’ll want you to explain concurrency and threading at a high level. This video isn’t meant to be a full-blown, in-depth coding tutorial. It’s meant to help newer developers understand the topic at a high level so they can explain it.
@charmisutariya7060
@charmisutariya7060 4 роки тому
Thank you Sean, These videos are clear and so very helpful.
@seanallen
@seanallen 4 роки тому
Happy to help, Charmi 😀
@charmisutariya7060
@charmisutariya7060 4 роки тому
@@seanallen Omg, I was just watching your videos right now (almost since morning) and seeing your reply, I'm like 🤩
@vaibhavdeshpande8643
@vaibhavdeshpande8643 5 років тому
Hey Sean, great videos... very helpful.... Need a video of concurrency and multithreading with GCD and OperationQueues comparison, what n how more flexibilities we get with OperationQueues, etc.
@seanallen
@seanallen 5 років тому
Good suggestion. I'll add it to the list!
@farmood100
@farmood100 6 років тому
Great job Allen. .......
@isaacclark9825
@isaacclark9825 6 років тому
Nice explanation. You convinced me that it was time to subscribe!
@seanallen
@seanallen 6 років тому
Man... that was a hard-earned subscriber, lol. Thanks Isaac! 😃
@isaacclark9825
@isaacclark9825 6 років тому
Lol! I am not much of a joiner. You gotta show me something!!
@poonamkanuga6127
@poonamkanuga6127 6 років тому
please do a video on GCD and Nsoperation queue.
@chillybean9662
@chillybean9662 6 років тому
Wow this is awesome Sean. Nice use of animations and your explanation is very clear. Keep up the good work, Nice one here!!
@seanallen
@seanallen 6 років тому
Thanks Chilly! This was a tough one to put together.
@chillybean9662
@chillybean9662 6 років тому
I must say you will make a good bootcamp instructor or teacher too lol.
@FRUITPUNCH2609
@FRUITPUNCH2609 6 років тому
you put in a lot of effort, thanks man!!!
@seanallen
@seanallen 6 років тому
Glad you enjoyed it!
@wilsonbalderrama
@wilsonbalderrama 6 років тому
wow impressive explanation Sean, good job!
@seanallen
@seanallen 6 років тому
Thanks Wilson... this one took some time to put together... Glad you enjoyed it!
@shubhpatni2123
@shubhpatni2123 6 років тому
Love your videos but please make this one with more code examples thank u
@jameelshehadeh9011
@jameelshehadeh9011 3 роки тому
very simplified and clear thank you Sean
@seanallen
@seanallen 3 роки тому
Glad it was helpful!
@michaelstram
@michaelstram 6 років тому
DispatchQueue and OperationQueue are so important to learn and understand as an iOS / macOS dev!
@seanallen
@seanallen 6 років тому
Agreed!
@michaelstram
@michaelstram 6 років тому
Udacity and the big nerd ranch book on iOS programming have great lessons GCD and when to use operation queue vs. dispatch queue. FLOW is key.
@sashakolsky
@sashakolsky 6 років тому
Hi Michael, I have the book, but didn't find anything on GDC there at all. Can you reference the pages or section? There are a couple of pages about OperationQueue, but nothing on dispatch that I could find.
@hugocoutinho3268
@hugocoutinho3268 5 років тому
Great explanations. Thank you
@seanallen
@seanallen 5 років тому
Happy to help.
@luciarigoni8289
@luciarigoni8289 Рік тому
Thank you so much for this video!
@seanallen
@seanallen Рік тому
Glad it was helpful!
@Jason021376
@Jason021376 4 роки тому
You stated that you never manually sent tasks to the background, so I am assuming that there are conditions when tasks are automatically sent to a background. What are these conditions?
@soulx520
@soulx520 6 років тому
Hey Sean, great explanation and for so many of your videos, your analogies are what helps people like me understand these concepts so here, your traffic example or your other video explaining class vs struct with sharing google docs vs sending an email. My question is when do you use .async and .sync? Difference? I can google but your explanations are really helpful. Thanks in advance.
@seanallen
@seanallen 6 років тому
Synchronous and Asynchronous are basically the same as serial and concurrent, respectively in the video. Something done synchronously is like serial. One thing at a time, and the next task doesn't start until the one before it finishes. Whereas Asynchronously is like concurrent, multiple actions happening at the same time.
@ahujapravir
@ahujapravir 4 роки тому
​@@seanallen Hey! also does sync vs async refers to the task execution on a thread level compared to serial concurrent which is on dispatch queue level? Like if we have a task/operation being submitted to a concurrent queue synchronously then does that mean that the task will be getting dispatched onto different threads, and those threads will get blocked until that task/operation has finished completely. That is, serial blocks queue from starting new tasks and sync blocks threads to include new tasks' execution in between by context switching? Or does sync also blocks the dispatch queue only from starting new tasks? And, sync/async also operate on dispatch queue level only?
@vprabhu2906
@vprabhu2906 3 роки тому
@Sean Allen Hi Sean , I watched ur tutorial s , helps a lot, But have a doubt on one thing # Dispatchqueue.main.async "main" was mentioned it was serial queue ( order execution ) so, what the next .async ( it's unorder execution ) I was confusing ,pls clarify
@cheesetoochalk
@cheesetoochalk 2 роки тому
Excellent job
@ekchhuon4976
@ekchhuon4976 5 років тому
Great expalanations
@technoforensics
@technoforensics 6 років тому
@Sean, Thank you. Appreciate it a lot.
@seanallen
@seanallen 6 років тому
Glad you enjoyed it Joash!
@karooki7219
@karooki7219 6 років тому
Hey Sean! Absolutely love your videos! Currently just went through a phone screen and 80% of the questions came from your videos so I'm really thankful! Just wondering, what you use to make your animations?
@seanallen
@seanallen 6 років тому
That's awesome to hear, Karo! Glad I could help in some way. Best of luck on the interview process! For the video animations I just used Key-Frame animations in Final Cut Pro.
@abdulazizalharbi6228
@abdulazizalharbi6228 3 роки тому
great explanation, now I know the differences between main and global (represent the threads on the device's processor), and concurrent and serial (represent the queue types in each thread ), hopefully I'm right But what I'm confused about, is when I see serial.async, I know serial queue is meant to be one task at a time, how could it be asynchronized? the same for concurrent.sync, the main purpose of the concurrent is to execute multiple tasks at one time, then why would we make it synchronized? Thank you Sean for your high-quality content best,
@waylans
@waylans 3 роки тому
You don't use the background thread when uploading or downloading data?
@ambujpunn
@ambujpunn 5 років тому
Great video Sean. I had a question: You mentioned that you don't manually put anything on the background queue as much...Why is that? I would say it is common practice to manually put API data fetching logic in the background queue. And the only reason one should have to call reloadData for the table view on the main queue is when something has already been put in the background queue (like a manual trigger to fetch data through some API)
@RevanthKausikan
@RevanthKausikan 4 роки тому
Sean, your thoughts on this pease?
@seanallen
@seanallen 6 років тому
Concurrency and Threading can be a tricky topic. Happy to help answer any questions in the comments!
@sashakolsky
@sashakolsky 6 років тому
Hi Sean, just to clarify, when we say DispatchQueue.main.async that async references the concurrent queue of the main thread, is that it? Does each thread has its own set of two queues (serial and concurrent)?
@victoreysner7630
@victoreysner7630 5 років тому
Excellent! Thanks for your video and work. But i think we need part 2 with this title. It video skip more detail about multithreading. For example what is deadlock, more detail about flexibilities with Operation and OperationQueue. More detail about API GCD. Maybe few word about api Thread and how depend Thread and DispatchQueue.
@vegitoblue4390
@vegitoblue4390 5 років тому
Awesome video Sean, thanks a ton.
@seanallen
@seanallen 5 років тому
Glad you liked it!
@stevengao8345
@stevengao8345 6 років тому
thanks for your time. i do have a question about uimapview, need it need to put to background thread ? if we put something on background thread, is there anything to do with weak reference ? so it may get dismissed and not occupy so many memory? sorry, i am a newbie, got all these silly question on my mind.
@seanallen
@seanallen 6 років тому
Hey Steven, this question is a little vague and hard to answer with out seeing your specific code. That being said, if you're handing your memory correctly and don't have retain cycles, what queue/thread it's on shouldn't make a difference.
@saadfurqan6200
@saadfurqan6200 6 років тому
Great job. well done and keep it up.
@seanallen
@seanallen 6 років тому
Thanks Saad!
@mrmillmill
@mrmillmill 2 роки тому
What are a few examples of when you would use the serial queue? Would it be when you’re reloading a table view on the main thread? What are some other examples? Also what are a few examples of tasks to execute on a concurrent queue?
@reyariass
@reyariass 5 років тому
If you have to send stuff to the main thread a lot, how is stuff sent to the background thread without sending it manually?
@monicaluo1122
@monicaluo1122 4 роки тому
It's a great video! Do you have a video about lock & deadlock, race condition(with more details)?
@seanallen
@seanallen 4 роки тому
Glad you liked it! I do not have a video on those topics.
@andressaneumann3454
@andressaneumann3454 3 роки тому
excellent video, thank u so much
@seanallen
@seanallen 3 роки тому
Happy to help, Andressa!
@eray9280
@eray9280 Рік тому
Hi Sean. Keep up the good work!
@seanallen
@seanallen Рік тому
Hey Eray... will do!
@krishnakirana8399
@krishnakirana8399 3 роки тому
In concurrency and asynchronous are the same? if not what is the difference?
@lennyports
@lennyports 3 роки тому
Hi Sean! Which tasks get executed on the background thread and which tasks on the main thread? You mention UI related tasks should get executed on the main thread, but I am struggling to understand which tasks automatically are executed in the background. Thanks for all of your help! I am huge fan on your videos.
@seanallen
@seanallen 3 роки тому
Hey Lenny, the classic example of the background thread tasks are network calls. Because downloading data from a server takes time (who knows how good the internet connection is), that goes on the background thread as to not disrupt the app running on the main thread.
@ashrafshakhatreh3609
@ashrafshakhatreh3609 3 роки тому
how to work on a specific thread of the background thread ?
@ko-eb6og
@ko-eb6og 6 років тому
Can i check somehow on which queue my code is?
@shubhammishra-zz1os
@shubhammishra-zz1os 5 років тому
You are the Best iOS Developer i have ever seen
@seanallen
@seanallen 5 років тому
Hehe, I appreciate the kind words, but I still have a lot to learn myself. 😀
@chaggan03
@chaggan03 5 років тому
What is the difference between gcd and queues??
@aleshanzlik9736
@aleshanzlik9736 6 років тому
Hello Sean, first of all thanks for great explanation. I've a question. I have whole bunch of data (around 300 images) to download and save to core data but when I save objects to core data on the main thread it takes so long and the UI gets frozen. Does that mean I can save core data inside "DispatchQueue.global(qos: .background).async" ?
@eduardoliveros
@eduardoliveros 6 років тому
I recommend split the process, for example download 10 object for time, and the others in a global queue
@eduardoliveros
@eduardoliveros 6 років тому
Great video Bro!
@seanallen
@seanallen 6 років тому
Thanks Eduardo!
@DewTime
@DewTime 5 років тому
I’m still confused because there’s a main thread and then there’s a main queue. And the there’s serial queues and concurrent queues. I don’t think you really tied everything together with dispatchqueue.main.async{}. Does the block of code have anything to do with the main thread or the main queue?
@amari9773
@amari9773 6 років тому
What monitor are you using? Love your setup.
@seanallen
@seanallen 6 років тому
Hey Julio, it's an LG 34 inch curved ultra wide. Can see more about it in my Dev Setup video: ukposts.info/have/v-deo/kpmKrJVrnJuAzqc.html
@amari9773
@amari9773 6 років тому
Sean Allen Sweet. Thanks!
@TheZorick
@TheZorick 4 роки тому
finally i undestand the dispatch queue two days ago, i trying to print the content size of tableview but idk it printed 0.0 and i think maybe the value is printed before the tableview load or get the total of content size. and i got the solution in stackoverflow which is to use main dispatch queue and its worked perfectly. so that the thread of print value has moved to main thread which is using the serial queue :)
@seanallen
@seanallen 4 роки тому
That's a big concept to understand. Glad you got it!
@valeriiazakharova4886
@valeriiazakharova4886 4 роки тому
thanks a lot :)
@bharatjuneja79
@bharatjuneja79 5 років тому
Can we call APIs in Concurrent Queue? If yes, then will it help in case we have multiple APIs on same screen. Thanks!
@seanallen
@seanallen 5 років тому
Yes, you typically make network calls on a background thread (which is concurrent), then once you've received all your data from those network calls, you update your UI on the Main Thread.
@andredouglas6201
@andredouglas6201 2 роки тому
Thanks man
@seanallen
@seanallen 2 роки тому
Happy to help, Andre.
@TheBooban
@TheBooban 3 роки тому
Whats the difference between Operation and NSOperation?
@mishaespinoza3900
@mishaespinoza3900 6 років тому
Excellent post production skills
@seanallen
@seanallen 6 років тому
Thanks Misha!
@TheCarlosAlfaro
@TheCarlosAlfaro 6 років тому
Hi Sean, what camera and microphone do you use for your videos?
@seanallen
@seanallen 6 років тому
I use a Canon EOS M3 and a simple RODE lapel mic.
@TheCarlosAlfaro
@TheCarlosAlfaro 6 років тому
Cool, it looks really nice! thank you!
@jamesqiu6715
@jamesqiu6715 6 років тому
You mixed up concurrency and parallism. And.... Without shared resource to protect, what is the CONDITION your thread race for to occupy it?
@benbejster7326
@benbejster7326 6 років тому
What would happen differently if the tableView was reloaded on the background thread?
@seanallen
@seanallen 6 років тому
It would take a lot longer to populate and would give your app the appearance of being really slow to load the images.
@dylanl9532
@dylanl9532 4 роки тому
In the example you gave, you should add [weak self] in, because the user may chooser to go to a different page while your json data is being loaded. Once it's loaded, self is already removed from memory therefore will cause an error
@seanallen
@seanallen 4 роки тому
This is correct
@Dineshk1389
@Dineshk1389 3 роки тому
picture can tell thousands words. that picture of express lane(main thread) can have two cars (tasks) side by side. but main thread is an expressway with just one lane so no two cars (tasks) go side by side.
@heyrahulrs
@heyrahulrs 6 років тому
Amazing video!!🍻
@seanallen
@seanallen 6 років тому
Thanks Rahul!
@cozziee92
@cozziee92 6 років тому
I experienced a bug recently which sort of made a concurrent queue to stop executing tasks altogether if the number of jobs submitted to it is >100ish. Can you throw some light on what might be causing this?
@seanallen
@seanallen 6 років тому
To be honest, Jatin, I'm not sure what could be causing that issue. Sorry I couldn't be of more help.
@roycheong8250
@roycheong8250 5 років тому
Excellent. Subscribed + Liked.
@seanallen
@seanallen 5 років тому
Thanks for the support, Roy 👍
@RostyslavKobizsky
@RostyslavKobizsky 2 роки тому
How about semaphores and berries?
@orlandog.rodriguez8837
@orlandog.rodriguez8837 6 років тому
So just to confirm, any code executed on DispatchQueue.main.async {...} will be done in order?
@seanallen
@seanallen 6 років тому
You're making sure that code gets executed on the main thread. Yes, whatever code you have in that block will be executed in order.
@maximkrouk1697
@maximkrouk1697 4 роки тому
Shouldn't You use [weak self] in your self.tableView.reloadData() example?
@cosmicjoshgaming3655
@cosmicjoshgaming3655 4 роки тому
I don't understand code ); Is there anyway you can show me your path so I code just like you ?
@ebukaegbunam4369
@ebukaegbunam4369 4 роки тому
you are an angel
@seanallen
@seanallen 4 роки тому
Happy to help!
@diakojafari2107
@diakojafari2107 2 роки тому
very good 👍
@tusharsingh2439
@tusharsingh2439 5 років тому
just a small trick that i use (only for small projects, maybe using Firebase, etc. ) I load all the JSON data on the initial VC and make a global variable storing all the JSON values , so whenever you need the values you can simply call the global variable on the main thread. Tough this isn't a good programming technique , it works good enough
@hanmoklee4055
@hanmoklee4055 3 роки тому
Thank god..
@aniketayachit2253
@aniketayachit2253 4 роки тому
I'm wondering why we use DispatchQueue.main.async() not DispatchQueue.main.sync()? I was searching for an answer. but did not get promising answer. Hope you can help me out?
@vprabhu2906
@vprabhu2906 3 роки тому
Even I do have confusion, Anything know about this..?
@techluthiers8189
@techluthiers8189 5 років тому
Sean, this video was 1000x times more powerful than the Stanford video out there in youtube for threads btw that video is more than an hour and it is not even 1%worth vs this. Again Thank you. Now, how do I start debugging something that is stuck somewhere in the mainThread (serial) while just opening a vc that hangs just after viewWillAppear()? Thanks for giving me any clue!
@seanallen
@seanallen 5 років тому
Glad you liked this video! It's one of my favorites as well. I would need more specifics on your issue to be able to help. It's pretty hard trying to help debug via UKposts comments 😀
@LukeSamkharadze
@LukeSamkharadze 2 роки тому
You didn't explain quite clearly, If we have 1 functions for sending tasks to main thread and 1 for background thread, then in which thread we are on?
@yesbolkulanbekov2878
@yesbolkulanbekov2878 6 років тому
Imho, one thing hard to understand for beginners is calling Concurrent Queues “queue”. You can’t relate to it to a real life queue. So, it means I was not cutting in line in cafeteria, I was just in a concurrent queue.
@nikinlug
@nikinlug 6 років тому
If you say that you never use DispatchQueue.global.. but you do use DispathQueue.main, then how do you use it? I mean the whole point of dispatching to the main is switching from another queue but you say you don't use it..
@seanallen
@seanallen 6 років тому
When using NSURLSession for network calls the downloads automatically happen on a background thread. Which is why I rarely move stuff to a background thread manually (manually is the key word there). The very common flow is to download some data from the internet, and then update your UI on the main thread using DispatchQueue.main.async.
@ruimao6191
@ruimao6191 6 років тому
A follow up question, if you don't manually specify DispathQueue.main, will the UI continue being updated on the background thread?
@sivakrishna5293
@sivakrishna5293 5 років тому
It's not safe to update your UI in background thread, cause it is unpredictable when your UI gets loaded and it's not recommended, sometimes your app may crash for doing UI stuff in background thread.
@CaffieneToCode
@CaffieneToCode 5 років тому
Why is UI updated on the main thread?
@pgrm1188
@pgrm1188 5 років тому
Let me respond you with an example. Let's say you are downloading a big file. You probably want to show the user a progress bar or something. Also, your download would probably be downloaded on a background thread (if not, you're clearly doing it wrong) and then you'd update the progress bar on the main thread. Apple decided that the main thread is mostly reserved for UI because you don't want to have an *unresponsive app* . So why update the UI on the main thread and not on a background thread? Exactly because of what I just said, and also because *the main thread is the one with the highest priority of them all* .
@paramveersingh3491
@paramveersingh3491 3 роки тому
Is main thread free all the time and everthing else is happening on the background thread
@seanallen
@seanallen 3 роки тому
UI stuff is happening on the main thread
@paramveersingh3491
@paramveersingh3491 3 роки тому
@@seanallen Ok thanks sir for helping
@HarshitKumar-br3iz
@HarshitKumar-br3iz 5 років тому
Nice video
@seanallen
@seanallen 5 років тому
Thanks 😀
"Поховали поруч": у Луцьку попрощались із ДВОМА Героями 🕯🥀 #герої #втрати
00:15
Телеканал Конкурент TV - новини Луцька та Волині
Переглядів 226 тис.
Кровосток - разговор с легендами / вДудь
2:12:57
McDonald’s MCNUGGET PURSE?! #shorts
00:11
Lauren Godwin
Переглядів 25 млн
Swift - Bounds vs. Frame - iOS Interview Question
8:00
Sean Allen
Переглядів 54 тис.
iOS Interview Questions and Answers 2017 - Swift  - Series Overview
11:42
When to Semaphore vs Dispatch Group! Careful Multithreaded Shared Resource
11:11
Lets Build That App
Переглядів 45 тис.
Swift Error Handling - Do, Try, Catch - iOS Interview Question Series
14:58
SwiftUI GeometryReader
27:53
Stewart Lynch
Переглядів 9 тис.
Swift Optionals - How to Unwrap (real examples)
14:20
Sean Allen
Переглядів 10 тис.
All New Atlas | Boston Dynamics
0:40
Boston Dynamics
Переглядів 5 млн
Нужен ли робот пылесос?
0:54
Катя и Лайфхаки
Переглядів 860 тис.
The PA042 SAMSUNG S24 Ultra phone cage turns your phone into a pro camera!
0:24
Нужен ли робот пылесос?
0:54
Катя и Лайфхаки
Переглядів 860 тис.