我在此代码的第一行收到以下错误:
Method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C
@objc func personsToFirstStep(persons: [Person]) { for person in persons { if !self.persons.contains(person) && person.ID != userID { self.persons.append(person) } } collectionVIEw.reloadData() collectionVIEwPlaceholder.hIDden = true collectionVIEw.hIDden = false collectionGradIEntVIEw.hIDden = false}
这个Person类:
class Person: Hashable { var intID: Int = 0 var ID: String = "" var name: String = "" var type: String = "" var hashValue: Int { return self.intID } init(ID: String,name: String,type: String) { self.ID = ID self.intID = Int(ID)! self.name = name self.type = type }}func ==(lhs: Person,rhs: Person) -> Bool { return lhs.intID == rhs.intID}你自己很好地解释了这个问题:
class Person: Hashable {
人不是NSObject.但Objective-C只能看到NSObject派生的类类型.因此,您的Person类型对Objective-C是不可见的.但是你的@objc func声明用于一个带有Person数组的函数 – 我们刚才说Person对Objective-C是不可见的.所以你的@objc func声明是非法的. Objective-C无法显示此功能,因为它无法显示其参数.
您需要将类声明更改为如下所示:
class Person: NSObject {
……然后你当然可以在班级的实施中做出任何必要的进一步调整.但是这种改变会使你的@objc func声明合法化. (NSObject是Hashable,所以进行这种调整所需的工作量可能不是很大.)
总结以上是内存溢出为你收集整理的Swift 2.0 Method无法标记为@objc,因为参数的类型无法在Objective-C中表示全部内容,希望文章能够帮你解决Swift 2.0 Method无法标记为@objc,因为参数的类型无法在Objective-C中表示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)