gpt4 book ai didi

core-data - SWIFT 中的核心数据 + NSFetchedResultsController

转载 作者:行者123 更新时间:2023-11-28 13:21:53 25 4
gpt4 key购买 nike

我会尽量让它变得尽可能简单我使用 NSFetchedResultsController 从核心数据中获取我的 cellForRowAtIndexPath 看起来像这样

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
let newEntry : Entry = fetchedResultController.objectAtIndexPath(indexPath) as Entry
cell.textLabel.text = newEntry.title
return cell
}

我的应用程序崩溃了

当我替换下面的行时

let newEntry : Entry = fetchedResultsController.objectAtIndexPath(indexPath) as Entry

通过这一行,应用程序可以记录填充 TableView ,没有错误,没有问题

let newEntry : AnyObject! = self.fetchedResultsController.objectAtIndexPath(indexPath)

问题是为什么 AnyObject 不是 Entry NSManagedObject

谢谢

最佳答案

NSFetchedResultsController 没有问题,但是Objective-C 需要识别你的NSManagedObject 子类。只需在您的 NSManagedObject 子类中添加 @objc(Entry) 即可:

@objc(Entry)
class Entry: NSManagedObject {
@NSManaged var title: String
}

关于core-data - SWIFT 中的核心数据 + NSFetchedResultsController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24783904/

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