31 lines
983 B
Swift
31 lines
983 B
Swift
//
|
|
// Feed+CoreDataClass.swift
|
|
// Reader
|
|
//
|
|
// Created by Shadowfacts on 1/9/22.
|
|
//
|
|
//
|
|
|
|
import Foundation
|
|
import CoreData
|
|
import Fervor
|
|
|
|
@objc(Feed)
|
|
public class Feed: NSManagedObject {
|
|
|
|
public func updateFromServer(_ serverFeed: Fervor.Feed) {
|
|
guard self.id == nil || self.id == serverFeed.id else { return }
|
|
self.id = serverFeed.id
|
|
self.title = serverFeed.title
|
|
self.url = serverFeed.url
|
|
self.lastUpdated = serverFeed.lastUpdated
|
|
// todo: check this
|
|
self.removeFromGroups(self.groups!.filtered(using: NSPredicate(format: "NOT id IN %@", serverFeed.groupIDs)) as NSSet)
|
|
let groupsToAddReq = Group.fetchRequest()
|
|
groupsToAddReq.predicate = NSPredicate(format: "id IN %@", serverFeed.groupIDs.filter { g in !self.groups!.contains { ($0 as! Group).id == g } })
|
|
let groupsToAdd = try! self.managedObjectContext!.fetch(groupsToAddReq)
|
|
self.addToGroups(NSSet(array: groupsToAdd))
|
|
}
|
|
|
|
}
|