34 lines
877 B
Swift
34 lines
877 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 {
|
|
|
|
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!
|
|
}
|
|
}
|
|
|
|
|
|
}
|