gpt4 book ai didi

ios - '#selector' 的参数未引用中的初始化程序或方法

转载 作者:行者123 更新时间:2023-11-28 19:34:03 27 4
gpt4 key购买 nike

我将我的项目从 Swift2.2 更新到 Swift3.0 但是 “Argument of '#selector' does not refer to an initializer or method” 收到问题。

这是代码:

for object in Students {
let sectionNumber = collation.section(for: object.firstName!, collationStringSelector: #selector(NSObjectProtocol.self))
sections[sections.count - 1 - sectionNumber].append(object)
}

enter image description here

最佳答案

class Person: NSObject {
@objc var name: String

init(name: String) {
self.name = name
}
}

let p = Person(name: "Alice")

let collation = UILocalizedIndexedCollation.current()
collation.section(for: p, collationStringSelector: #selector(getter: Person.name))

这也很好,因为 Selector 来自 Objective-C。我们需要 :NSObject@objc

关于ios - '#selector' 的参数未引用中的初始化程序或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989897/

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