swift - 未捕获的异常 'NSInvalidArgumentException' ,原因 : '-[SubResultComponent setDate:]: unrecognized selector sent to instance 0x60000046b640'

标签 swift core-data appdelegate nsexception

我遇到一个错误,但不确定如何修复。

这里有错误

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SubResultComponent setDate:]: unrecognized selector sent to instance 0x60000046b640'

这是子结果组件

extension SubResultComponent {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<SubResultComponent> {
        return NSFetchRequest<SubResultComponent>(entityName: "SubResultComponent")
    }

    @NSManaged public var date: String?
    @NSManaged public var price: NSDecimalNumber?

}

这是我调用设定日期的地方

func updateUI() {

    guard rateLog != nil else {

        return
    }

    // Update cell UI
    self.dateLabel.text = rateLog?.date
    self.priceLabel.text = numberFormatter.string(from: (rateLog?.price)!)
}

最佳答案

@NSManaged 的作用类似于 Objective C 版本的 dynamic;这是对编译器的 promise ,该对象将在运行时具有这些属性。它实际上并不具有这些属性。为此,需要在核心数据模型文件中正确设置这些属性。使用编辑器的“创建 NSManagedObject 子类...”选项极大地有助于保持代码和模型同步。

关于swift - 未捕获的异常 'NSInvalidArgumentException' ,原因 : '-[SubResultComponent setDate:]: unrecognized selector sent to instance 0x60000046b640' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50536410/

相关文章:

swift - 自定义 UIButton 作为导航项后退按钮工作,但不显示

ios - 尝试复制 GMSPlacesClient : autoCompleteQuery function to populate a UITableView manually

objective-c - 通过引用 ObjectiveC 方法快速传递数组

ios - 将通用数组转换为 NSOrderedSet?

ios - 为什么在 applicationProtectedDataWillBecomeUnavailable 中 isProtectedDataAvailable 不正确?

ios - 如何在 iOS 的一个地方处理常见错误(可以在一个地方的每个 UIViewController 中引发)?

push-notification - 控制在SWIFT中收到推送通知后加载哪个 View Controller

ios - 检测所有应用程序的手势

ios - 使用 swift 将 JSON 检索到的 int32 解析为核心数据类

iphone - 用于操作 UITableViewController 中核心数据的开源 UI 框架