Tip:
Highlight text to annotate it
X
Today I'm going to show you how to use Grand Central Dispatch.
I've started a simple application to show you
how it works without using Grand Central Dispatch
The Application freezes when we hit sleep
until it's done sleeping.
so this is the code right here sleep for five seconds.
now you can go ahead
Sender
set
title
sleeping
for state UIControlStateNormal
and now lets disable the button also
enabled space = space
now for the dispatch code.
the dispatch
and it's working on
_t
my_queue_t
=
dispatch
get global queue
dispatch
queue
priority default
0
now
dispatch
async
my_queue_t
go ahead and hit tab and then enter.
and a ; after the )
and we can say sleep 5
this is where your network code would go
we don't want to use anything that starts with UI
the class and you are actually get set
text
buttons and stuff like that while you're on a different thread
and to get back to the main queue dispatch
async
dispatch
get
main_queue
standard set
title
sleep
for state UIControlStateNormal
sender.enabled = YES;
and
that should be it. Let's go ahead and run it.
Now when you hit sleep you can still move the slider around.
when it's done it says sleep again
that's all there is
to grand central dispatch
thanks for watching!
Check out my website at zerosgamedesign.com