Method dispatch in Swift

Rathish Kannan
1 min readDec 16, 2020
  1. GCD vs Dispatch queue
  • OperationQueue internally uses Grand Central Dispatch and on iOS.
  • OperationQueue gives you a lot more control over how your operations are executed. You can define dependencies between individual operations for example, which isn't possible with plain GCD queues. It is also possible to cancel operations that have been enqueued in an OperationQueue (as far as the operations support it). When you enqueue a block in a GCD dispatch queue, it will definitely be executed at some point.
  • To sum it up, OperationQueue can be more suitable for long-running operations that may need to be cancelled or have complex dependencies. GCD dispatch queues are better for short tasks that should have minimum performance and memory overhead.
  • Ref: https://stackoverflow.com/questions/7078658/operation-queue-vs-dispatch-queue-for-ios-application

3. Static func vs Class func

  • class functions are dynamically dispatched and can be overridden by subclasses.
  • static func is same as final class func Because it is final, we can not override it in subclass.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response