Arrays 将UILocalizedIndexedCollation.section(用于:collationStringSelector:)与结构数组一起使用
假设我有一个结构数组,如下所示:Arrays 将UILocalizedIndexedCollation.section(用于:collationStringSelector:)与结构数组一起使用,arrays,swift,struct,Arrays,Swift,Struct,假设我有一个结构数组,如下所示: struct Record { let name: String } let array = [Record(name: "John"), Record(name: "Jim"), Record(name: "Bob")] 我想使用UILocalizedIndexedCollation.sectionfor:collationStringSelector获取每个元素的索引。问题是,当我通过时: #selector(getter: record.nam
struct Record {
let name: String
}
let array = [Record(name: "John"), Record(name: "Jim"), Record(name: "Bob")]
我想使用UILocalizedIndexedCollation.sectionfor:collationStringSelector获取每个元素的索引。问题是,当我通过时:
#selector(getter: record.name)
返回以下错误:
“selector”的参数引用了未公开给
目标-C
有没有办法将结构中的实例值公开给选择器?注意:我传递的结构在我的整个应用程序中被广泛使用,我真的不想将其更改为类将结构变量转换为NSString并使用NSString的方法/变量之一是一项解决问题的工作:
let index = UILocalizedIndexedCollation.current().section(for: (record.name as NSString), collationStringSelector: #selector(getter: NSString.uppercased))
有没有办法将结构中的实例值公开给选择器?不可以。选择器永远不能使用Swift结构。您可能需要一个包装器类来处理UILocalizedIndexedCollation。