frenzy-ios/Persistence/Sources/Persistence/Item+CoreDataClass.swift

33 lines
883 B
Swift

//
// Item+CoreDataClass.swift
// Reader
//
// Created by Shadowfacts on 1/9/22.
//
//
import Foundation
import CoreData
import Fervor
@objc(Item)
public class Item: NSManagedObject {
public func updateFromServer(_ serverItem: Fervor.Item) {
guard self.id == nil || self.id == serverItem.id else { return }
self.id = serverItem.id
self.author = serverItem.author
self.content = serverItem.content
self.title = serverItem.title
self.read = serverItem.read ?? false
self.published = serverItem.published
self.url = serverItem.url
if self.feed?.id != serverItem.feedID {
let feedReq = Feed.fetchRequest()
feedReq.predicate = NSPredicate(format: "id = %@", serverItem.feedID)
self.feed = try! self.managedObjectContext!.fetch(feedReq).first!
}
}
}