Hi, Alex here from rebeloper.com and welcome back to the channel
and welcome back to this awesome tutorial series on DuckUI.
Now what is DuckUI? Well it is SwiftUI in UiKit, well kind of and today we
are going to talk about delays, okay. So let's jump right in the code.
Great! Now I have just recently added DispachQueueHeleper that will help us with
delays in the latest version of DuckUI. So let us just open up terminal and
update our project here. So type in CD and a space and what we want to do
here is just a drag and drop our root folder of our project. Hit return. Type in
pod update and if you are just jumping right into this video tutorial
go ahead and take a look at the previous episodes where I talk about how you can
create this project and yeah what is DuckUI and why you should
definitely use it alongside of course UIKit, okay. Let's just wait for that
to update and let me just talk a little bit about today's basically lesson.
We want to sometimes delay on purpose or we want to just grab something from the
background thread and presented on the main thread. Well that is where
DipatchQueueHelper will come in handy and that is already in DuckUI and
as you can see this version 0.3.12 that I have updated too. So yeah go ahead
and do that if you're just installing for the first time yeah you should get
this or later version. So let's just first of all go to product and clean our
build folder and want is once it is cleaned it command B so it builds our
project and yeah we should see everything
to be okay. It is complaining about DuckUI no such module but yeah as
you could see it already it disappeared and yeah as you can see here we have
a D dispatch queue helper and that is what we are going to use. So let's say we have
some data coming in and we want to display it after one second. Well that is
not always the case this is kind of an edge case but sometimes you do want to
do that so this is how you could do it make sure you import DuckUI into
your view controller. Let me just add this here so D underscore Dispach patch queue
helper and add a dot there and as you can see we can delay by seconds and that
is double with a completion or we can delay by seconds with the
dispatch level and of course completion. Now the dispatch level is set to main by
default if you want to do this on the background set then just simply select
that and I will select this second one so just so you can see the options.
So the seconds let's say, let's have here 3 seconds so we can basically see
all of this and the dispatch queue level let' add a dot here so we can see our
options background made user initiated user interactive utility. We will choose
main or we could just simply delete this dispatch level option because the app
domain is the default value and code let's say lock success and I will be
talking about this log in a later video but I believe I also have a separate
video on the YouTube channel about this but yeah just stay tuned and subscribe
to our channel and hit that notification bar to get notified of the new video.
So let's see logging after that they 3 seconds.
Great and just so we know that when we started our viewdidload let's log here
a simple line and let's see what should we add in here. Start it, start it.
Okay! That is pretty nice. So let's just hit command R or click on the build and
then Run button and build has succeeded that's always a good sign and yeah we
can see here that started, yeah and after three seconds logging after three
seconds has been printed in the console log. So that is pretty straightforward
and if you take a look at the dispatch queue helper you will see how this is
achieved but in my opinion this is pretty amazing just we can do this with
one line of code and with a completion that is pretty awesome in my opinion.
Okay! Now if you wanted to you could go to a background thread or in some cases
let's say you fetch an image from a server and you do that on a background
thread usually that's what you do and you want to then present it on a UI
element, a UIImageView for example then you should basically come
to the main thread and you could do this by delaying let's say zero seconds but
so you just don't have to let me just jump into definition. So you don't have
to just jump into the main thread with the dispatch queue. This is pretty
straightforward. I believe and it has some very useful use cases. Now that is
it for me today. I hope you enjoyed this video if you did go ahead and give it a
thumbs up, subscribe to the channel and of course get that notification bell so
you can get the newest videos on your feed. If you don't do that and you are
still subscribed you may not get the new as they do come out daily on the channel.
Now being that set I will see you in the next one.