//
//  Task+Ext.swift
//  PQSpeed
//
//  Created by SanW on 2020/12/8.
//  Copyright © 2020 BytesFlow. All rights reserved.
//

import Foundation

// MARK: - URLSessionDataTask添加url跟taskId

/// URLSessionDataTask添加url跟taskId

private var taskId_key: Void?
private var url_key: Void?
private var pathExtension_key: Void?

extension URLSessionTask {
    /// 任务url
    var taskUrl: String {
        set {
            objc_setAssociatedObject(self, &url_key, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
        get {
            return objc_getAssociatedObject(self, &url_key) as? String ?? ""
        }
    }

    /// 任务唯一标示
    var taskId: String {
        set {
            objc_setAssociatedObject(self, &taskId_key, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
        }
        get {
            return objc_getAssociatedObject(self, &taskId_key) as? String ?? ""
        }
    }
}
