executeFetchRequest 不返回 NSManagedObject 子类 [英] executeFetchRequest doesn't return the NSManagedObject subclass

查看:31
本文介绍了executeFetchRequest 不返回 NSManagedObject 子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这适用于 XCode 6 和 Swift...

This is for XCode 6 and Swift...

我正在尝试向托管对象上下文发出提取请求,但它没有返回正确的子类.

I'm trying to make a fetch request to the managed object context but it's not returning the correct subclass.

我已经将数据模型数据建模器配置中的子类设置为我的自定义子类的名称,并且在代码中,它扩展了 NSManagedObject 类.

I have already set the subclass in the data model data modeler configuration to the name of my custom subclass and in the code, it is extending the NSManagedObject class.

有什么想法吗?

推荐答案

刚刚找到解决方案.

我必须添加 @objc 属性以允许该类与 Objective-C 兼容.

I had to add the @objc attribute to allow the class to be compatible with Objective-C.

现在获取请求返回了 Tasks[]

import Foundation
import CoreData

@objc(Task) // make compatible with objective-c
class Task : NSManagedObject
{
    @NSManaged var note: String!
    @NSManaged var completed: Bool
}

参考:https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-XID_36

这篇关于executeFetchRequest 不返回 NSManagedObject 子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆