最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【整理】swift中QOS_CLASS_BACKGROUND vs DISPATCH_QUEUE_PRIORITY_BACKGROUND

Swift crifan 748浏览 0评论

关于GCD时,

QOS_CLASS_BACKGROUND

感觉是属于QOS==quality of service系列的

DISPATCH_QUEUE_PRIORITY_BACKGROUND

不知道是什么关系

后来通过点击

    let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)

中的dispatch_get_global_queue看到源码:

/*!
 * @function dispatch_get_global_queue
 *
 * @abstract
 * Returns a well-known global concurrent queue of a given quality of service
 * class.
 *
 * @discussion
 * The well-known global concurrent queues may not be modified. Calls to
 * dispatch_suspend(), dispatch_resume(), dispatch_set_context(), etc., will
 * have no effect when used with queues returned by this function.
 *
 * @param identifier
 * A quality of service class defined in qos_class_t or a priority defined in
 * dispatch_queue_priority_t.
 *
 * It is recommended to use quality of service class values to identify the
 * well-known global concurrent queues:
 *  – QOS_CLASS_USER_INTERACTIVE
 *  – QOS_CLASS_USER_INITIATED
 *  – QOS_CLASS_DEFAULT
 *  – QOS_CLASS_UTILITY
 *  – QOS_CLASS_BACKGROUND
 *
 * The global concurrent queues may still be identified by their priority,
 * which map to the following QOS classes:
 *  – DISPATCH_QUEUE_PRIORITY_HIGH:         QOS_CLASS_USER_INITIATED
 *  – DISPATCH_QUEUE_PRIORITY_DEFAULT:      QOS_CLASS_DEFAULT
 *  – DISPATCH_QUEUE_PRIORITY_LOW:          QOS_CLASS_UTILITY
 *  – DISPATCH_QUEUE_PRIORITY_BACKGROUND:   QOS_CLASS_BACKGROUND
 *
 * @param flags
 * Reserved for future use. Passing any value other than zero may result in
 * a NULL return value.
 *
 * @result
 * Returns the requested global queue or NULL if the requested global queue
 * does not exist.
 */
@available(iOS 4.0, *)
@warn_unused_result
public func dispatch_get_global_queue(identifier: Int, _ flags: UInt) -> dispatch_queue_t!

可以看出来是:

DISPATCH_QUEUE_PRIORITY_HIGH==QOS_CLASS_USER_INITIATED

DISPATCH_QUEUE_PRIORITY_DEFAULT== QOS_CLASS_DEFAULT

DISPATCH_QUEUE_PRIORITY_LOW== QOS_CLASS_UTILITY

DISPATCH_QUEUE_PRIORITY_BACKGROUND==QOS_CLASS_BACKGROUND

的。

建议使用QOS系列的。

所以建议使用:

let backgroundQueue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)

而不是:

    let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)

转载请注明:在路上 » 【整理】swift中QOS_CLASS_BACKGROUND vs DISPATCH_QUEUE_PRIORITY_BACKGROUND

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
60 queries in 0.127 seconds, using 18.62MB memory