Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 按标题字符串对节进行自定义排序_Ios_Swift_Dictionary_Grouping - Fatal编程技术网

Ios 按标题字符串对节进行自定义排序

Ios 按标题字符串对节进行自定义排序,ios,swift,dictionary,grouping,Ios,Swift,Dictionary,Grouping,我有一个按节模型标题排序的节数组。我想能够自定义排序的标题这些。也就是说,选择哪个节具有哪个索引XPath 以下是结构: fileprivate struct Section: Decodable, Hashable { let title: String let offers: [Offer] } 以下是我如何将数据分组并将其放入各个部分: func makeSection(offer: Offer) -> String { return offer.secti

我有一个按节模型标题排序的节数组。我想能够自定义排序的标题这些。也就是说,选择哪个节具有哪个
索引XPath

以下是结构:

fileprivate struct Section: Decodable, Hashable {
    let title: String
    let offers: [Offer]
}
以下是我如何将数据分组并将其放入各个部分:

func makeSection(offer: Offer) -> String {
    return offer.section
}

fileprivate func createSections(from offers: [Offer]) {
    let groups = Dictionary(grouping: offers) { (offer) in
        return makeSection(offer: offer)
    }
    self.sections = groups.map { (key, values) in
        return Section(title: key, offers: values)
    }
}

我知道我可以使用“排序依据”功能,但是,这只能按字母顺序排序。我想我可能需要一个名为index的变量在我的section结构中?

您可以编写任何函数来
排序(by:)
。因此,基本上您不希望根据
标题
字母顺序对
节进行排序,而是保留您已有的offers数组的顺序?