gpt4 book ai didi

swift - RxSwift 可观察数组排序

转载 作者:可可西里 更新时间:2023-11-01 00:36:38 25 4
gpt4 key购买 nike

我正在尝试对可观察数组进行排序,但运气不好(RxSwift n00b)

let items = [AnyObject]? 
let locations = Observable.just(items)

我想在位置上实现这样的目标

items.sortInPlace({$0.name < $1.name})

任何指点将不胜感激!

最佳答案

这是我的解决方案

Observable
.just(items)
.map({ (items) -> [AnyObject] in
return items.sorted(by: { (item1, item2) -> Bool in
return item1.name < item2.name
})
})
....

关于swift - RxSwift 可观察数组排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36807392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com