gpt4 book ai didi

ios - swift -CoreData

转载 作者:行者123 更新时间:2023-11-29 01:54:59 24 4
gpt4 key购买 nike

我有一个自定义的 NSManagedObject:

import Foundation
import CoreData
@objc(Article)

class Article: NSManagedObject {

@NSManaged var articleID: String
@NSManaged var isFavorite: Bool
init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?, articleID: String, isFavorite: Bool) {
super.init(entity: entity, insertIntoManagedObjectContext: context)
self.articleID = articleID
self.isFavorite = isFavorite
}

override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) {
super.init(entity: entity, insertIntoManagedObjectContext: context)
}
}

但是当我尝试向 CoreData 添加新条目时出现错误:

let articleEntity = NSEntityDescription.entityForName("Article", inManagedObjectContext: self.context!)
let newArticle = Article(entity: articleEntity!, insertIntoManagedObjectContext: self.context!)
newArticle.articleID = articleID
newArticle.isFavorite = true

Use of unresolved identifier 'Article'

最佳答案

从上面的信息来看,您似乎没有在 coredata 的配置中为实体添加类。确保您已在 .xcdatamodeld 文件的配置中将类映射到实体。您可以查看以下示例。

enter image description here

关于ios - swift -CoreData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30966167/

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