PT.BUZOO INDONESIA is No1 Japanese offshore development company in Indonesia.
We are professional of web solution and smartphone apps. We can support Japanese, English and Indonesia.
We are hiring now at http://buzoo.co.id/
2. What is protocols?
ď‚›
ď‚›
ď‚›
Protocols is methods (like other method in
objective C), like a regulations needed to
implement a class.
For example : In traffic rules, there are some
law required for someone who want to drive
a car, like having a driving license, obey the
traffic lights, etc.
A protocol is a group of related properties
and methods that can be implemented by
any class.
3. Why use protocols?
ď‚› They
are more flexible than a normal
class.
 Produce a reusable code (you don’t
need to import your class controller), since
they let you to reuse a single API
declaration in completely unrelated class.
7. Protocols Implementation on
Controller (Cont’d)
ď‚›
Implement the protocol method on your viewcontroller.m
(don’t forget to include, since it’s required, or your app will
crash)
8. Conclusions
ď‚› Using
this protocols function, you can
create your own library functions (or even
framework)
ď‚› Protocols can make your code even
easier because of it’s own flexibility
10. Concurrency Programming :
Dispatch Queue (GCD)
Grand Central Dispatch (GCD) takes the
thread management code you would
normally write in your own applications and
moves that code down to the system level.
All you have to do is define the tasks you
want to execute and add them to an
appropriate dispatch queue. GCD takes
care of creating the needed threads and
of scheduling your tasks to run on those
threads.
11. What is GCD for ?
ď‚› Schedules
your tasks, and execute them
in the order in which they arrive. They can
either concurrent or serial. A concurrent
queue will execute many jobs
simultaneously (do not wait with the next
job until any previous ones finish), a serial
queue will only execute one job at a time.
(FIFO)
12. Types of GCD
ď‚› The
main queue : task submitted to the
main thread of our app.
ď‚› Global queues : task submitted to the
entire process.
ď‚› Private queues : queues that created by
our own with dispatch_queue_create,
Can be used as synchronization
mechanism.
13. When to use?
For example, for database accessing.
Database is a sensitive process, you have to
prevent deadlock (accessing and update
from many connections) that’s why database
connection and access can be accessed
one at a time.
Thus, you have to make a schedule and
queue for any task that want to access the
database.
14. Private queue
ď‚›
You can create queue by make an identifier.
ď‚›
This will create a private queue with synchronized
queue
You can implement the queue and add tasks with
following code :
ď‚›
15. Dispatch_Sync &
Dispatch_async
ď‚›
ď‚›
ď‚›
Dispatch sync is mutex lock. In other words, it will wait the task
to complete and then add another task
Dispatch async is not mutex lock. In other words, it won’t wait
for another task to completely finished, it will run another task.
Example :
It may print 2413 or 2143 or 1234 but 1 always before 3
It will always print 1234