gpt4 book ai didi

ios - Swift - 带有 Objective-C 选择器 '*()' 的方法 '*' 与具有相同 Objective-C 选择器的父类(super class) '*' 的 'NSObject' 的 getter 冲突

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:52 24 4
gpt4 key购买 nike

自从将我的 xcode 更新到 6.3.1 后,我收到了这条错误消息。

/Users/MNurdin/Documents/iOS/xxxxx/Models/Message.swift:46:10: Method 'hash()' with Objective-C selector 'hash' conflicts with getter for 'hash' from superclass 'NSObject' with the same Objective-C selector

我的代码

var hash_ : UInt

func hash() -> UInt {
return UInt(hash_);
}

最佳答案

详细说明:@property(readonly) NSUInteger hashNSObject 的Objective-C 属性,这意味着为该变量创建了一个getter,即哈希()

您现在尝试定义一个具有相同名称和相同参数(无)但返回类型不同的方法(UInt 而不是 NSUInteger,这将是Int 在 swift 中。)。因此您会收到给定的错误。要解决该问题,您现在有两个选择:

  • 将返回类型更改为 Int -> 这将覆盖预定义的哈希函数
  • 选择不同的方法名或添加参数

关于ios - Swift - 带有 Objective-C 选择器 '*()' 的方法 '*' 与具有相同 Objective-C 选择器的父类(super class) '*' 的 'NSObject' 的 getter 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30018403/

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