使用DispatchQueue判断当前队列是主队列

extension DispatchQueue {

    private static var token: DispatchSpecificKey<()> = {

        let key = DispatchSpecificKey<()>()

        DispatchQueue.main.setSpecific(key: key, value: ())

        returnkey

    }()


    static var isMain: Bool {

        return DispatchQueue.getSpecific(key: token) != nil

    }

}

你可能感兴趣的:(使用DispatchQueue判断当前队列是主队列)