Skip to content

Instantly share code, notes, and snippets.

@speaktoalvin
Created October 14, 2015 07:20
Show Gist options
  • Save speaktoalvin/15fd16c8c75cffef2641 to your computer and use it in GitHub Desktop.
Save speaktoalvin/15fd16c8c75cffef2641 to your computer and use it in GitHub Desktop.
Grand Central Dispatch
// An easy way to get different queue's in your project.
//
// GCDMan.swift
// GCDGhost
//
// Created by Alvin Varghese on 15/09/15.
// Copyright (c) 2015 iDreamCode. All rights reserved.
//
import Foundation
import UIKit
public class DSL {
class func mainQueue() -> dispatch_queue_t {
return dispatch_get_main_queue()
}
class func userInteractiveQueue() -> dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)
}
class func userInitiatedQueue() -> dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)
}
class func utilityQueue() -> dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_UTILITY, 0)
}
class func backgroundQueue() -> dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)
}
class func defualtQueue() -> dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0)
}
class func unSpecifiedQueue() -> dispatch_queue_t {
return dispatch_get_global_queue(QOS_CLASS_UNSPECIFIED, 0)
}
}
class Thread {
//MARK: Asynchronous Queue
func async(name : String,block : dispatch_block_t) -> () {
return dispatch_async(dispatch_queue_create(name, nil), block)
}
//MARK: Asynchronous Queue With Attributes
func async(name : String, attribute : dispatch_queue_attr_t, block : dispatch_block_t) -> () {
return dispatch_async(dispatch_queue_create(name, nil), block)
}
//MARK: Main Queue
func main(block : dispatch_block_t) -> () {
return dispatch_async(DSL.mainQueue(), block)
}
//MARK: Background Queue
func background(block : dispatch_block_t) -> () {
return dispatch_async(DSL.backgroundQueue(), block)
}
//MARK: Utility Queue
func utility(block : dispatch_block_t) -> () {
return dispatch_async(DSL.utilityQueue(), block)
}
//MARK: User Interactive Queue
func userInteractive(block : dispatch_block_t) -> () {
return dispatch_async(DSL.userInitiatedQueue(), block)
}
//MARK: User Initiated Queue
func userInitiated(block : dispatch_block_t) -> () {
return dispatch_async(DSL.userInitiatedQueue(), block)
}
//MARK: Unspecified Queue
func unspecified(block : dispatch_block_t) -> () {
return dispatch_async(DSL.unSpecifiedQueue(), block)
}
//MARK: Default Queue
func defualt(block : dispatch_block_t) -> () {
return dispatch_async(DSL.defualtQueue(), block)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment