在变量 <[Element]> 上使用排序的 RxSwift 错误
RxSwift error using Sort on Variable<[Element]>
我有一个这样的数组:
var arrayPoints:Variable<[Point]>?
稍后用户可以像这样对列表进行排序:
func orderPointsByDistance(){
self.arrayPoints?.value.sort{ [=11=].stringDistance.compare(.stringDistance) == .orderedAscending }
}
但是我收到这个错误:
fatal error: Executing on backgound thread.
Please use MainScheduler.instance.schedule to schedule work on main thread.: file /Users/dasilvans/Desktop/GeoPlay/Pods/RxSwift/RxSwift/Rx.swift, line 23
在某种程度上我发现了错误,但不知道如何解决。
有什么建议吗?
试试这个我认为你在这样做时阻塞了 rx
let stuff = Array(self.arrayPoints?.value)
stuff.sort{ [=10=].stringDistance.compare(.stringDistance) == .orderedAscending }
self.arrayPoints?.value = stuff
或者是
的问题
DispatchQueue.main.async {
}
我有一个这样的数组:
var arrayPoints:Variable<[Point]>?
稍后用户可以像这样对列表进行排序:
func orderPointsByDistance(){
self.arrayPoints?.value.sort{ [=11=].stringDistance.compare(.stringDistance) == .orderedAscending }
}
但是我收到这个错误:
fatal error: Executing on backgound thread.
Please use MainScheduler.instance.schedule to schedule work on main thread.: file /Users/dasilvans/Desktop/GeoPlay/Pods/RxSwift/RxSwift/Rx.swift, line 23
在某种程度上我发现了错误,但不知道如何解决。 有什么建议吗?
试试这个我认为你在这样做时阻塞了 rx
let stuff = Array(self.arrayPoints?.value)
stuff.sort{ [=10=].stringDistance.compare(.stringDistance) == .orderedAscending }
self.arrayPoints?.value = stuff
或者是
的问题DispatchQueue.main.async {
}