转换为 Swift3 错误

Posted

技术标签:

【中文标题】转换为 Swift3 错误【英文标题】:Convert to Swift3 error 【发布时间】:2017-03-12 06:28:04 【问题描述】:

Xcode 转换为 Swift 3.0 语法后,出现以下错误:

错误:无法使用类型为“(qos_class_t)”的参数列表调用类型“Int”的初始化程序 DispatchQueue.global(优先级:Int(DispatchQoS.QoSClass.userInitiated.rawValue)).async ^

注意:“Int”的重载存在这些部分匹配的参数列表:(Int64)、(Word)、(UInt8)、(Int8)、(UInt16)、(Int16)、(UInt32)、(Int32)、 (UInt64), (UInt), (Int), (Float), (Double), (Float80), (String, radix: Int), (CGFloat), (NSNumber) DispatchQueue.global(priority: Int(DispatchQoS.QoSClass.userInitiated.rawValue)).async

转换后的语法:

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) 

    if searchText == "" 
        self.filteredSymbols = self.symbols
        self.alphabeticSymbolCollection.reloadData()
     else 
        DispatchQueue.global(priority: Int(DispatchQoS.QoSClass.userInitiated.rawValue)).async 
            let fs = self.filterContentForSearchText(searchText)
            DispatchQueue.main.async 
                self.filteredSymbols = fs

                self.searchActive = true

                self.alphabeticSymbolCollection.reloadData()
            
        
    


转换前的语法:

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) 

    if searchText == "" 
        self.filteredSymbols = self.symbols
        self.alphabeticSymbolCollection.reloadData()
     else 
        dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) 
            let fs = self.filterContentForSearchText(searchText)
            dispatch_async(dispatch_get_main_queue()) 
                self.filteredSymbols = fs

                self.searchActive = true

                self.alphabeticSymbolCollection.reloadData()
            
        
    


【问题讨论】:

How do I dispatch_sync, dispatch_async, dispatch_after, etc in Swift 3?的可能重复 【参考方案1】:

很简单

DispatchQueue.global(qos: .userInitiated).async  

【讨论】:

以上是关于转换为 Swift3 错误的主要内容,如果未能解决你的问题,请参考以下文章

Swift 3.0 转换错误

Swift 3 RKObjectRequestOperation 返回错误无法转换类型为 RKObjectRequestOperation

无法将类型值转换为 UINavigationController swift3

转换为 Swift 3.0 时出现多个问题

Swift 3 转换获取 'Int1' 不能转换为 'Bool'

无法将类型的值转换为UINavigationController swift3